Comments (5)
This is new to me. ASAP does play the domains game though, so I would not be surprised whether continuation storage worked or not. Please follow-up if you can. If we donβt have to entrain a dependency, and with good specs, I would not mind supporting it at least to the extent that it is an experiment worth trying.
from asap.
Here is what it would take to make asap CLS-aware (replacing the current definition of the asap function):
function asap(task) {
if (isNodeJS && process.domain) {
task = process.domain.bind(task);
}
if (isNodeJS && process.namespaces) {
var namespaces = Object.keys(process.namespaces);
var length = namespaces.length;
for (var i = 0; i < length; i++) {
if (namespaces[i].active) task = namespaces[i].bind(task);
}
}
tail = tail.next = {task: task, next: null};
if (!flushing) {
requestFlush();
flushing = true;
}
};
@ForbesLindesay It also would be fairly simple to write a shim module that wraps around asap
(there are a bunch of CLS shims already) if you don't see the value of making asap support something that isn't part of Node core:
require('continuation-local-storage');
var asap = require('asap');
module.exports = function clsAsap(task) {
if (process.namespaces) {
var namespaces = Object.keys(process.namespaces);
var length = namespaces.length;
for (var i = 0; i < length; i++) {
if (namespaces[i].active) task = namespaces[i].bind(task);
}
}
return asap(task);
}
For now, CLS is Node-only, so I'm not really sure how much value you get out of using asap
over setImmediate
, but this is how you make it play nice with CLS!
from asap.
Oh, and I should point out that I already made a shim for Q which is only really necessary when you're using some other module that messes with continuation chains (like node-redis
or node-mysql
).
from asap.
With apologies, my inclination is to not do anything special for this kind of extension.
from asap.
Thanks, that seems fair. I may revisit this and consider producing something like asap-cls
if I find myself really needing it.
from asap.
Related Issues (20)
- Browserify Support HOT 15
- Cross library interleaving can cause node 10's nextTick limit to be hit. HOT 1
- Publish a new version HOT 4
- function to change rawAsap.capacity value must be added HOT 3
- Consider using Promise.prototype.then HOT 4
- asap queue can be effectively overflown (using [email protected]) HOT 2
- Usability in development mode with thrown errors HOT 5
- Browser field contains invalid route in npm HOT 8
- Microtask queue can be made faster HOT 4
- asap uses timer, not MutationObserver, in Safari HOT 1
- react-native throw Error when importing asap HOT 8
- Chrome + postMessage = slow HOT 1
- Source is poinitng to internal uber repo HOT 3
- npm published version 2.05 is not in git HOT 1
- Browser-asap requiring wrong raw file (non-browser version). HOT 4
- Does asap have an ECCN? HOT 2
- Contributors? HOT 1
- Use queueMicrotask? HOT 2
- esbuild fails: "browser" field is not according to spec
- TypeError: t.observe is not a function. (In 't.observe(l,{characterData:!0})', 't.observe' is undefined) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asap.