Gathering detailed insights and metrics for @vritant/async-action-pump
Gathering detailed insights and metrics for @vritant/async-action-pump
Gathering detailed insights and metrics for @vritant/async-action-pump
Gathering detailed insights and metrics for @vritant/async-action-pump
npm install @vritant/async-action-pump
Typescript
Module System
Node Version
NPM Version
71.4
Supply Chain
96.2
Quality
75.9
Maintenance
100
Vulnerability
99.6
License
TypeScript (94.45%)
JavaScript (5.55%)
Total Downloads
1,545
Last Day
1
Last Week
5
Last Month
28
Last Year
282
MIT License
92 Commits
2 Watchers
7 Branches
1 Contributors
Updated on Aug 08, 2023
Minified
Minified + Gzipped
Latest Version
0.0.11
Package Id
@vritant/async-action-pump@0.0.11
Unpacked Size
61.11 kB
Size
11.30 kB
File Count
39
NPM Version
9.6.7
Node Version
18.17.1
Published on
Sep 13, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-28.6%
5
Compared to previous week
Last Month
-50.9%
28
Compared to previous month
Last Year
-77.7%
282
Compared to previous year
3
A package containing utilities to dynamically queue async operations.
Can be used to dynamically queue and run asynchronous operations
1import { AsyncActionPump, LogMessage } from '@vritant/async-action-pump' 2 3// Create options for async action pump. This is optional. 4const options = { 5 logger: (logMessage: LogMessage) => { 6 if (logMessage.type === 'log') { 7 // verbose logs from the async action pump. 8 console.log(logMessage.message); 9 } else if (logMessage.type === 'error') { 10 // errors encountered in the async action pump. 11 // These contain errors not caught by posted actions. 12 console.error(logMessage.error); 13 } 14 } 15} 16 17// Create an AsyncActionPump 18const asyncActionPump = AsyncActionPump.create<number>(options); 19 20// Post an async action into the queue. 21// Since the queue is empty, the operation will immediately run. 22asyncActionPump.post(async () => await someAsyncOperation()); 23 24// Post another async action into the queue. 25// Since an operation was already posted previously, this will 26// only run once the previous operation is complete. 27asyncActionPump.post(async () => await someAsyncOperation()); 28 29// Wait for all operations so far to be complete. 30await asyncActionPump.waitForAllActions(); 31 32// Post an action and wait for it's completion. 33// This can be used to run async actions in order and get their result. 34const res = asyncActionPump.postAsync(() => Promise.resolve(1)); 35console.log(res); // res = 1
Can be used to dynamically queue and synchronous operations asynchronously
1import { ActionPump } from '@vritant/async-action-pump' 2 3// Create an ActionPump 4const actionPump = ActionPump.create<void>(); 5 6// Post an action into the queue. 7// Since the queue is empty, the operation will immediately run asynchronously. 8actionPump.post(() => someOperation()); 9 10// Post another action into the queue. 11// Since an operation was already posted previously, this will 12// only run once the previous operation is complete. 13actionPump.post(() => someOperation());
Can be used to dynamically queue and run asynchronous cancellable operations. It is similar
to the AsyncActionQueue
, but adds the ability to cancel queued actions as well.
1import { CancellableAsyncActionPump } from '@vritant/async-action-pump' 2 3// Create an CancellableAsyncActionPump 4const cancellableAsyncActionPump = CancellableAsyncActionPump<void>.create(); 5 6// Post a cancellable async action into the queue. 7// Since the queue is empty, the operation will immediately run. 8cancellableAsyncActionPump.post( 9 async (cancellationToken: ICancellationToken) => 10 await someCancellableOperation(cancellationToken) 11 ); 12 13// Cancel all running and queued actions so far in the queue. 14// NOTE: this does not terminate the running action. The cancellation 15// token used by the running action is signalled a cancellation. 16// It is the action's responsibility to terminate. No future actions will be 17// run until the running action terminates. 18cancellableAsyncActionPump.cancelQueuedAndRunningOperations();
No vulnerabilities found.
No security vulnerabilities found.