最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用nodejs AsyncLocalStorage有什么好处?

网站源码admin40浏览0评论

使用nodejs AsyncLocalStorage有什么好处?

使用nodejs AsyncLocalStorage有什么好处?

不明白使用AsyncLocalStorage的目的。

例如:

const store = { id: 1 };
// Replaces previous store with the given store object
asyncLocalStorage.enterWith(store);
asyncLocalStorage.getStore(); // Returns the store object
someAsyncOperation(() => {
  asyncLocalStorage.getStore(); // Returns the same object
}); 

为什么我们只使用普通的 javascript 而不是它?

let store;
export const getStore = () => store;

export const setStore = (value) => {
  store = value;
};
回答如下:
发布评论

评论列表(0)

  1. 暂无评论