You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Class, instance, and static method decorators on classes: synchronization mode & concurrency mode.
12
-
2.This library implements a FIFO task queue for O(1) speed. Using built-in JavaScript array will have O(n) issue.
13
-
3.Optional parameter, `inheritPreErr`. If current task is waiting for previous tasks, set it as `true` to inherit the error of the previous task and the task will not be executed and throw a custom error `new PreviousError(task.preError.message ?? task.preError)`. If this parameter is omitted or set as `false`, the task will continue whether previous tasks happen errors or not.
14
-
4.Optional parameter, `noBlockCurr`. Set it as `true` to forcibly execute the current task in the another (microtask) execution of the event loop. This is useful if you pass a sync function as the first task but do not want it to block the current event loop.
12
+
2.Wrap a function to a new queue-ready async function. It is convenient to re-use this function. Also, it is able to pass arguments and get return value for each task function.
13
+
3.Support `async function`, a `promise-returning` function, and a `sync` function.
14
+
4.Sub queues system (via tags).
15
15
5. Support Browser and Node.js.
16
16
6. Fully Written in TypeScript and its `.d.ts` typing is out of box. JavaScript is supported, too.
17
-
7.Wrap a function to a new queue-ready async function. It is convenient to re-use this function. Also, it is able to pass arguments and get return value for each task function.
18
-
8.Support `async function`, a `promise-returning` function, and a `sync` function.
19
-
9.Sub queues system (via tags).
20
-
10.Well tested.
17
+
7.This library implements a FIFO task queue for O(1) speed. Using built-in JavaScript array will have O(n) issue.
18
+
8.Well tested.
19
+
9.Optional parameter, `inheritPreErr`. If current task is waiting for previous tasks, set it as `true` to inherit the error of the previous task and the task will not be executed and throw a custom error `new PreviousError(task.preError.message ?? task.preError)`. If this parameter is omitted or set as `false`, the task will continue whether previous tasks happen errors or not.
20
+
10.Optional parameter, `noBlockCurr`. Set it as `true` to forcibly execute the current task in the another (microtask) execution of the event loop. This is useful if you pass a sync function as the first task but do not want it to block the current event loop.
21
21
22
22
## Installation
23
23
@@ -31,13 +31,13 @@ Either `npm install d4c-queue` or `yarn add d4c-queue`. Then import this package
The code snippet is from [embedded-pydicom-react-viewer](https://github.com/grimmer0125/embedded-pydicom-react-viewer). Some function only can be executed after init function is finished.
283
283
284
284
```typescript
285
-
constd4c=newD4C();
285
+
constd4c=newD4C()
286
286
exportconstinitPyodide=d4c.wrap(async () => {
287
287
/** init Pyodide*/
288
-
});
288
+
})
289
289
290
290
/** without d4c-queue, it will throw exception while being called
@@ -302,20 +302,20 @@ It is similar to causality. Sometimes two function which access same data within
302
302
303
303
```typescript
304
304
constfunc1=async () => {
305
-
console.log("func1 start, execution1 in event loop")
306
-
awaitfunc3();
307
-
console.log('func1 end, should not be same event loop execution1');
308
-
};
305
+
console.log('func1 start, execution1 in event loop')
306
+
awaitfunc3()
307
+
console.log('func1 end, should not be same event loop execution1')
308
+
}
309
309
310
310
constfunc2=async () => {
311
-
console.log('func2');
312
-
};
311
+
console.log('func2')
312
+
}
313
313
314
314
asyncfunction testRaceCondition() {
315
-
func1();// if add await will result in no race condition
316
-
func2();
315
+
func1() // if add await will result in no race condition
316
+
func2()
317
317
}
318
-
testRaceCondition();
318
+
testRaceCondition()
319
319
```
320
320
321
321
`func2` will be executed when `func1` is not finished.
@@ -330,7 +330,7 @@ No race condition on two API call in `Express`, any API will be executed one by
330
330
/** Express case */
331
331
app.post('/testing', async (req, res) => {
332
332
// Do something here
333
-
});
333
+
})
334
334
```
335
335
336
336
However, race condition may happen on two API call in `Apollo`/`NestJS`.
@@ -344,7 +344,7 @@ const resolvers = {
344
344
Query: {
345
345
books: async () =>books,
346
346
},
347
-
};
347
+
}
348
348
```
349
349
350
350
Two Apollo GraphQL queries/mutations may be executed concurrently, not like Express. This has advantage and disadvantage. If you need to worry about the possible race condition, you can consider this `d4c-queue` library, or `Databasetransaction` or [async-mutex](https://www.npmjs.com/package/async-mutex). You do not need to apply `d4c-queue` library on top API endpoint always, just apply on the place you worry about.
@@ -354,15 +354,15 @@ Two Apollo GraphQL queries/mutations may be executed concurrently, not like Expr
354
354
The below shows how to make `helloquery` become `synchronized`. Keep in mind that `@synchronized` should be below `@Query`.
Copy file name to clipboardExpand all lines: package.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "d4c-queue",
3
-
"version": "1.6.5",
3
+
"version": "1.6.7",
4
4
"description": "A task queue executes tasks sequentially or concurrently. Wrap an async/promise-returning/sync function as a queue-ready async function for easy reusing. Support passing arguments/getting return value, @synchronized/@concurrent decorator, Node.js/Browser.",
0 commit comments