mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
43 lines
911 B
TypeScript
43 lines
911 B
TypeScript
import PQueue = require('p-queue');
|
|
|
|
const queue = new PQueue({concurrency: 1});
|
|
|
|
queue.add(() => Promise.resolve('sindresorhus.com')).then((sindre) => {
|
|
const str: string = sindre;
|
|
});
|
|
|
|
Promise.resolve((): Promise<string> => Promise.resolve('unicorn'))
|
|
.then(task => queue.add(task, {priority: 5}))
|
|
.then(unicorn => {
|
|
const str: string = unicorn;
|
|
});
|
|
|
|
queue.onEmpty().then(() => {
|
|
});
|
|
queue.clear();
|
|
|
|
let num: number;
|
|
num = queue.size;
|
|
num = queue.pending;
|
|
|
|
class QueueClass implements PQueue.QueueClass<{ any: string }> {
|
|
private queue: Array<() => void>;
|
|
|
|
size = 0;
|
|
|
|
constructor() {
|
|
this.queue = [];
|
|
}
|
|
|
|
enqueue(run: () => void, options: { any: string }) {
|
|
this.queue.push(run);
|
|
}
|
|
|
|
dequeue() {
|
|
return this.queue.shift();
|
|
}
|
|
}
|
|
|
|
const queue2 = new PQueue({queueClass: QueueClass});
|
|
queue2.add(() => Promise.resolve(), {any: 'hi'});
|