question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Difference with async-local-storage

See original GitHub issue

Can someone explain what is the difference between this library compared to https://github.com/vicanso/async-local-storage ? That library seems super simple.

I checked other solutions as we are having issues with destroying the namespace. Is destroying the namespace necessary on every request? Here is our middleware:

return async function(ctx, next) {
      const namespace = continuationLocalStorage.createNamespace('session');

      try{
        await new Promise(namespace.bind(function(resolve, reject) {
          namespace.set('request_id', ctx.request.header['x-request-id']);

          next().then(resolve).catch(reject);
        }));
      } catch(error) {
        throw error;
      } finally {
        continuationLocalStorage.destroyNamespace('session');
      }
    };

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Jeff-Lewiscommented, Nov 2, 2017

At first glance and without comparing in detail the async_hook event state management of async-local-storage, I assume for the latest node 8 versions, it and cls-hooked would behave the same.

One clear difference is cls-hooked provides backward compatibility with node 6 & 7 using AsyncWrap when running in those versions. It also provides the same interface as node-continuation-local-storage to make it easier for devs to try.

As for destroying namespaces, its not required but I guess it depends how you’re using it. I’m not sure what framework your middleware example is from, but usually namespaces are created sparingly, such as a “sessions” namespace, while contexts are created on that namespace for things like requests and sessions.

Btw, I love the simple and elegant code of async-local-storage… it makes me want to rewrite cls-hooked… when days start to have 36 hours in them…

0reactions
Jeff-Lewiscommented, Feb 20, 2018

@blacksonic Closing for now. Let me know if you have any issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js 14 & AsyncLocalStorage: Share a context between ...
AsyncLocalStorage is used to share data between asynchronous calls. This can be considered as a global variable related to a particular ...
Read more >
Asynchronous context tracking | Node.js v19.3.0 Documentation
It is similar to thread-local storage in other languages. The AsyncLocalStorage and AsyncResource classes are part of the node:async_hooks module: import { ...
Read more >
What's Async Local Storage in Node.js v14? - freeCodeCamp
Introducing Async Local Storage – Storage for asynchronous tasks. Consider a web server like Apache running PHP for hosting a website. When PHP ......
Read more >
Async local storage - AdonisJS
It is similar to thread-local storage in other languages." To simplify the explanation further, AsyncLocalStorage allows you to store a state when executing...
Read more >
Logging with Pino and AsyncLocalStorage in Node.js
Proper logging can be the difference between a lousy dump of debug statements and a powerful debugging tool that helps you find bugs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found