Commit 1374e7a
fix: Chain natively for Promise instances, side-chain for subclasses/thenables
Mirror the behaviour of Node.js core diagnostics_channel tracePromise:
- Native Promise (promise.constructor === Promise): chain via .then() and
return the chained promise. Safe because there is no subclass API to
preserve and the native .then() returns a native Promise.
- Promise subclass or other thenable: side-chain .then() purely for the
asyncStart/asyncEnd event callbacks, then return the original promise
unchanged. This preserves any subclass-specific methods on the return
value (e.g. Anthropic SDK's APIPromise.withResponse()).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent bb5e08b commit 1374e7a
1 file changed
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
397 | 420 | | |
398 | 421 | | |
399 | 422 | | |
| |||
0 commit comments