![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
The purpose with this module is to share contexts across async (and sync) calls. Contexts are accessed by keys and can be nested. It is an alternative to the deprecated domain. It is based on async_hooks that were introduced in node 8. Beware that that the async_hooks are still experimental in nodejs.
A typical scenario is when you need to share context in a request handler.
let http = require('http');
let cls = require('node-cls');
let server = http.createServer(function (request, response) {
let context = cls.create('request-context');
context.id = 1;
context.request = request;
context.response = response;
context.run(doWork);
})
server.listen(8080)
function doWork() {
let context = cls.get('request-context');
context.response.end(`End: ${context.id}`) //End: 1
}
Context is retained in async calls.
let cls = require('node-cls');
let context = cls.create('myContext');
context.run(() => {
context.name = 'George';
setTimeout(onTimeout, 300);
});
function onTimeout() {
let context = cls.get('myContext');
console.log(context.name); //George
}
Contexts can be nested, even on the same key.
let cls = require('node-cls');
let context = cls.create('myContext');
context.run(async () => {
context.name = 'George';
let context2 = cls.create('myContext');
await context2.run(onNested);
console.log(context.name) //George
});
async function onNested() {
await Promise.resolve();
let context = cls.get('myContext');
console.log(context.name); //undefined
context.name = 'John Nested';
setTimeout(onTimeout, 300);
}
function onTimeout() {
let context = cls.get('myContext');
console.log(context.name); //John Nested
}
In node 12 and above you can start a context directly instead of wrapping it in the run function. The start function returns a promise. You can leave the current context by calling exit.
let cls = require('node-cls');
async function main() {
let context = cls.create('myContext');
context.name = 'George';
await context.start();
let context2 = cls.create('myContext');
context2.name = 'John Nested';
await context2.start();
console.log(cls.get('myContext').name); //John Nested
cls.exit('myContext');
console.log(cls.get('myContext').name); //George
cls.exit('myContext');
console.log(cls.get('myContext')); //undefined
}
main();
FAQs
Continuation Local Storage based on async_hooks
The npm package node-cls receives a total of 3,761 weekly downloads. As such, node-cls popularity was classified as popular.
We found that node-cls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.