cntx 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +8 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cntx",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "create and use context for async functions in node",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/readme.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Async Context For Node
2
2
 
3
- ## Why
3
+ Create global context for async function call chain.
4
+ [![npm version](https://badge.fury.io/js/cntx.svg)](https://badge.fury.io/js/cntx)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
6
 
5
- When dealing with nested async functions (like in request handlers), it is often necessary to pass context from one function to the next. This can be cumbersome and error prone. You can't use a global variable because it will be overwritten by concurrent requests.
7
+ ## Purpose
6
8
 
7
- With the power of node's async hooks, `cntx` provides a way to store and retrieve context without passing it around as a parameter. With every async function call, the context is automatically passed to the next function in the call chain.
9
+ `cntx` is a lightweight npm package that simplifies the management of context in nested async functions, particularly in scenarios like request handlers. It eliminates the need for passing context as parameters or relying on global variables, which can lead to errors and conflicts in concurrent environments.
8
10
 
9
- `cntx` is meant to be simple and lightweight with easy to use API. If you need multiple namespaces, you can build on top of `cntx` to create your own context manager.
11
+ By utilizing Node's async hooks, `cntx` automatically propagates context to the subsequent async functions in the call chain. It offers an easy-to-use API and can serve as a foundation for building custom context managers with multiple namespaces.
10
12
 
11
13
  ## Installation
12
14
 
@@ -16,7 +18,7 @@ npm install cntx --save
16
18
 
17
19
  ## Usage
18
20
 
19
- You'd need to call `cntx.enable()` once at the beginning of your program to enable async hooks.
21
+ To enable async hooks, call `cntx.enable()` at the beginning of your program.
20
22
 
21
23
  ```js
22
24
  import { cntx } from 'cntx';
@@ -24,7 +26,7 @@ import { cntx } from 'cntx';
24
26
  cntx.enable();
25
27
  ```
26
28
 
27
- To initialize context, you can use `cntx({key: value})` to initialize context for the current async call chain.
29
+ You can use `cntx({key: value})` to initialize context for the current async call chain.
28
30
  Calling `cntx()` with no arguments will return the current context.
29
31
 
30
32
  ### Example