1.0.0 • Published 1 year ago

@lzptec/ctx v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@lzptec/ctx WIP

Dead simple context manager for Nodejs

import { AsyncCTX, AsyncContext, ContextToken, Context } from '@lzptec/ctx';

const token = new ContextToken<number>();
const tokenWithDefault = new ContextToken<number>(() => 123);
const context = new AsyncContext();

const printContextValue = () => {
    console.log(context.get(token));
};

const run = () => {
    await context.run(() => {
        printContextValue(); // Print undefined

        // Async Context
        context.set(token, 987);

        printContextValue(); // Print token value 987
    });

    // Outside Async Context 
    printContextValue(); // throw a ReferenceError
};

run();
1.0.0

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.4

2 years ago

0.0.2-0

3 years ago

0.0.1-1

3 years ago

0.0.1-0

3 years ago

0.0.1

3 years ago