mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-13 01:05:37 +02:00
fix: Move more directories
This commit is contained in:
17
cloud/packages/core/src/context.ts
Normal file
17
cloud/packages/core/src/context.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
export function createContext<T>() {
|
||||
const storage = new AsyncLocalStorage<T>();
|
||||
return {
|
||||
use() {
|
||||
const result = storage.getStore();
|
||||
if (!result) {
|
||||
throw new Error("No context available");
|
||||
}
|
||||
return result;
|
||||
},
|
||||
provide<R>(value: T, fn: () => R) {
|
||||
return storage.run<R>(value, fn);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user