@wry/context
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -13,2 +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; | ||
export declare function wrapYieldingFiberMethods<F extends Function>(Fiber: F): F; |
@@ -149,16 +149,23 @@ var currentContext = null; | ||
// remains coherent across any yields. | ||
var wrappedFibers = []; | ||
function wrapYieldingFiberMethods(Fiber) { | ||
function wrap(obj, method) { | ||
var fn = obj[method]; | ||
obj[method] = function () { | ||
return noContext(fn, arguments, this); | ||
// There can be only one implementation of Fiber per process, so this array | ||
// should never grow longer than one element. | ||
if (wrappedFibers.indexOf(Fiber) < 0) { | ||
var wrap = function (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"); | ||
wrappedFibers.push(Fiber); | ||
} | ||
// 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"); | ||
return Fiber; | ||
} | ||
export { Slot, asyncFromGen, bind, noContext, setTimeoutWithContext as setTimeout, wrapYieldingFiberMethods }; |
@@ -153,14 +153,21 @@ 'use strict'; | ||
// remains coherent across any yields. | ||
var wrappedFibers = []; | ||
function wrapYieldingFiberMethods(Fiber) { | ||
function wrap(obj, method) { | ||
var fn = obj[method]; | ||
obj[method] = function () { | ||
return noContext(fn, arguments, this); | ||
// There can be only one implementation of Fiber per process, so this array | ||
// should never grow longer than one element. | ||
if (wrappedFibers.indexOf(Fiber) < 0) { | ||
var wrap = function (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"); | ||
wrappedFibers.push(Fiber); | ||
} | ||
// 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"); | ||
return Fiber; | ||
} | ||
@@ -167,0 +174,0 @@ |
{ | ||
"name": "@wry/context", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"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": "26e4fbd9bc9b9c9bac12cce8dd09243605d170bf" | ||
"gitHead": "3a0643ee8dda643e9ac20249442f3ea6ecc1bc8d" | ||
} |
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
21384
408