1.0.1 • Published 1 year ago

function-contexts v1.0.1

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

Function Contexts

React like contexts for sync and async functions.

Example

import { createFunctionContext, getFunctionContext } from "function-contexts";

const kMyContext = createFunctionContext<number>();

function printContextValue() {
    console.log(`MyContext value: ${getFunctionContext(kMyContext)}`)
}

async function withContext() {
    printContextValue();
    await new Promise(resolve => setTimeout(resolve, 1000));
    printContextValue();
}

async function main() {
    await kMyContext.run(withContext, 1234);
}

main().catch(error => {
    console.error("main() encountered a critical error: %o", error);
});
1.0.1

1 year ago

1.0.0

1 year ago