Skip to content

Commit accbd97

Browse files
authored
avoid returning nested promises (#66)
1 parent 2168509 commit accbd97

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
### [2.1.3] 2023-02-22
9+
- Accept only `async` functions as a parameter to `Queue.run()` and avoid returning nested promises
10+
811
### [2.1.2] 2023-02-02
912
- Move the debug statements to `rollup.config.mjs` to eliminate `process` references from the output file
1013

@@ -22,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2225
# [2.0.0] 2023-01-19
2326
- Almost complete rewrite in TypeScript
2427
- Use `PriorityQueue` from `typescript-collection`
25-
- O(log(n)) in all cases
28+
- `O(log(n))` in all cases
2629
- Switch to mocha and test CJS/ES6/TS
2730
- Many bugs and edge cases fixed
2831
- The preferred way to import is now via the named export but the default export is still there
@@ -34,7 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3437
## [1.2.0] 2021-06-02
3538

3639
### Added
37-
- Add a run() method
40+
- Add a `run()` method
3841

3942
### [1.1.1] 2020-06-13
4043

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class Queue<T = unknown> {
167167
* @param {number} [priority=0] Optional priority, -1 is higher priority than 1
168168
* @return {Promise<any>} Resolved when the task has finished with the return value of fn
169169
*/
170-
run<U>(job: () => U, priority?: number): Promise<U> {
170+
run<U>(job: () => Promise<U>, priority?: number): Promise<U> {
171171
const prio = priority ?? 0;
172172
const id = Symbol();
173173
return this.wait(id as T, prio)

test/ts.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ describe('TS import', () => {
1010

1111
q.wait(Symbol(), 0);
1212

13-
const s: Promise<symbol> = q.run(() => Symbol());
13+
const s: Promise<symbol> = q.run(() => Promise.resolve(Symbol()));
1414
assert.instanceOf(s, Promise<symbol>);
1515

16-
const t: Promise<symbol> = q.run(() => Symbol(), 12);
16+
const t: Promise<symbol> = q.run(() => Promise.resolve(Symbol()), 12);
1717
assert.instanceOf(t, Promise<symbol>);
1818
});
1919

@@ -23,10 +23,10 @@ describe('TS import', () => {
2323

2424
q.wait(Symbol() as unknown, 0);
2525

26-
const s: Promise<symbol> = q.run(() => Symbol());
26+
const s: Promise<symbol> = q.run(() => Promise.resolve(Symbol()));
2727
assert.instanceOf(s, Promise<symbol>);
2828

29-
const t: Promise<symbol> = q.run(() => Symbol(), 12);
29+
const t: Promise<symbol> = q.run(() => Promise.resolve(Symbol()), 12);
3030
assert.instanceOf(t, Promise<symbol>);
3131
});
3232
});

0 commit comments

Comments
 (0)