File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 * A Promise subclass with an extra method, similar to Anthropic SDK's APIPromise.
88 * The instrumented wrapper must preserve the original return type so callers
99 * can still access subclass-specific methods like `.withResponse()`.
10- *
11- * NOTE: This function is intentionally NOT async. Async functions always wrap
12- * their return value in a native Promise, losing the subclass type. The real-
13- * world scenario (e.g. Anthropic SDK's APIPromise) uses a non-async function
14- * that explicitly constructs and returns a Promise subclass instance.
1510 */
1611class ExtendedPromise extends Promise {
1712 withResponse ( ) {
1813 return this . then ( result => ( { data : result , response : { status : 200 } } ) )
1914 }
2015}
2116
17+ /**
18+ * NOTE: Intentionally NOT async. Async functions always wrap their return value
19+ * in a native Promise, losing the subclass type. The real-world scenario
20+ * (e.g. Anthropic SDK's APIPromise) uses a non-async function that explicitly
21+ * constructs and returns a Promise subclass instance.
22+ */
2223function fetch ( url ) {
2324 return new ExtendedPromise ( resolve => resolve ( 42 ) )
2425}
You can’t perform that action at this time.
0 commit comments