@wry/context
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -13,1 +13,2 @@ /// <reference types="node" /> | ||
export declare function asyncFromGen<TArgs extends any[], TResult>(genFn: (...args: TArgs) => IterableIterator<TResult>): (...args: TArgs) => Promise<TResult>; | ||
export declare function wrapYieldingFiberMethods(Fiber: any): void; |
@@ -146,3 +146,19 @@ var currentContext = null; | ||
} | ||
// If you use the fibers npm package to implement coroutines in Node.js, | ||
// you should call this function at least once to ensure context management | ||
// remains coherent across any yields. | ||
function wrapYieldingFiberMethods(Fiber) { | ||
function wrap(obj, method) { | ||
var fn = obj[method]; | ||
obj[method] = function () { | ||
return noContext(fn, arguments, this); | ||
}; | ||
} | ||
// These methods can yield, according to | ||
// https://github.com/laverdet/node-fibers/blob/ddebed9b8ae3883e57f822e2108e6943e5c8d2a8/fibers.js#L97-L100 | ||
wrap(Fiber, "yield"); | ||
wrap(Fiber.prototype, "run"); | ||
wrap(Fiber.prototype, "throwInto"); | ||
} | ||
export { Slot, asyncFromGen, bind, noContext, setTimeoutWithContext as setTimeout }; | ||
export { Slot, asyncFromGen, bind, noContext, setTimeoutWithContext as setTimeout, wrapYieldingFiberMethods }; |
@@ -150,2 +150,18 @@ 'use strict'; | ||
} | ||
// If you use the fibers npm package to implement coroutines in Node.js, | ||
// you should call this function at least once to ensure context management | ||
// remains coherent across any yields. | ||
function wrapYieldingFiberMethods(Fiber) { | ||
function wrap(obj, method) { | ||
var fn = obj[method]; | ||
obj[method] = function () { | ||
return noContext(fn, arguments, this); | ||
}; | ||
} | ||
// These methods can yield, according to | ||
// https://github.com/laverdet/node-fibers/blob/ddebed9b8ae3883e57f822e2108e6943e5c8d2a8/fibers.js#L97-L100 | ||
wrap(Fiber, "yield"); | ||
wrap(Fiber.prototype, "run"); | ||
wrap(Fiber.prototype, "throwInto"); | ||
} | ||
@@ -157,1 +173,2 @@ exports.Slot = Slot; | ||
exports.setTimeout = setTimeoutWithContext; | ||
exports.wrapYieldingFiberMethods = wrapYieldingFiberMethods; |
{ | ||
"name": "@wry/context", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"author": "Ben Newman <ben@eloper.dev>", | ||
@@ -31,3 +31,3 @@ "description": "Manage contextual information needed by (a)synchronous tasks without explicitly passing objects around", | ||
}, | ||
"gitHead": "cec6db29c1dcc43333f87ef00f9acdbc98b8930e" | ||
"gitHead": "26e4fbd9bc9b9c9bac12cce8dd09243605d170bf" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20544
394