UNPKG

1.6 kBJavaScriptView Raw
1var Fiber = require('fibers');
2// HOTFIX for node-fibers problem.
3// I have not prepared a repro unit test yet. In the meanwhile,
4// here is the gist of the problem:
5// A problem can occur if a node.js process has a node_modules tree that
6// contains multiple copies of node-fibers, whether the same version or not.
7// For instance, a project depends on two top-level modules which each
8// depend on node-fibers, such that 'npm install' installs two copies of
9// node-fibers. Furthermore, both of these copies are required() during execution.
10// In this scenario, the expected control flow of the process can be corrupted.
11// In one observed case, resuming a suspended fiber actually transfers control
12// to the code encapsulated in a completely different fiber.
13// The problem vanishes if we ensure that only one instance of node-fibers gets
14// used throughout the process. The following lines do this by caching a
15// node-fibers instance globally on first require(), and reusing that instance
16// for all subsequent require()s.
17// NB: This is a workaround, not a complete fix! If modules other than asyncawait
18// use node-fibers, then the process may still end up using multiple instances of
19// node-fibers during execution. This needs investigating in node-fibers itself.
20// I intend to create a cut-down repro and raise an issue in the node-fibers project.
21if (!global.asyncawait)
22 global.asyncawait = {};
23if (!global.asyncawait.Fiber)
24 global.asyncawait.Fiber = Fiber;
25var result = global.asyncawait.Fiber;
26module.exports = result;
27//# sourceMappingURL=fibers.js.map
\No newline at end of file