From 8d0e1d66a2e7abead10f9c694bee7ff4c3799b3f Mon Sep 17 00:00:00 2001 From: odex Date: Fri, 5 Mar 2021 23:35:45 +0800 Subject: [PATCH] chore: ignore lib --- lib/index.cjs.js | 78 ------------------------------------------------ lib/index.d.ts | 31 ------------------- lib/index.esm.js | 74 --------------------------------------------- lib/utils.d.ts | 1 - 4 files changed, 184 deletions(-) delete mode 100644 lib/index.cjs.js delete mode 100644 lib/index.d.ts delete mode 100644 lib/index.esm.js delete mode 100644 lib/utils.d.ts diff --git a/lib/index.cjs.js b/lib/index.cjs.js deleted file mode 100644 index 4da7103..0000000 --- a/lib/index.cjs.js +++ /dev/null @@ -1,78 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -function callHook(hook, ...args) { - if (hook) { - return hook(...args); - } -} - -class Queue { - constructor(concurrency, config = {}) { - this.total = 0; - this.done = 0; - this.running = 0; - this.concurrency = concurrency; - this.queue = config.queue || []; - this.finalTask = config.finalTask; - this.total += this.queue.length; - this.onError = config.onError; - return this; - } - static of(concurrency = 1, config) { - return new Queue(concurrency, config); - } - static Promise(concurrency, config) { - return new Promise((resolve, reject) => { - if (!config.queue.length) { - resolve(); - return; - } - const t = Queue.of(concurrency, Object.assign({ onError: reject, finalTask: resolve }, config)); - t.next(); - }); - } - pushTask(task) { - this.total++; - this.queue.push(task); - this.next(); - } - next() { - while (this.running < this.concurrency && this.queue.length) { - const task = this.queue.shift(); - task() - .then(() => { - this.running--; - this.done++; - this.next(); - if (this.isDone()) { - callHook(this.finalTask); - } - }) - .catch((err) => { - callHook(this.onError, err); - }); - this.running++; - } - } - isDone() { - return this.running === 0 && this.queue.length === 0; - } - /** - * 等待队列完成 - */ - allDone() { - return new Promise((resolve, reject) => { - if (this.isDone()) { - return resolve(); - } - else { - this.finalTask = resolve; - this.onError = reject; - } - }); - } -} - -exports.Queue = Queue; diff --git a/lib/index.d.ts b/lib/index.d.ts deleted file mode 100644 index cae3f9d..0000000 --- a/lib/index.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -declare type Task = () => Promise; -interface TaskQueueConfig { - finalTask?: () => void; - onError?: (e: Error) => void; - queue?: Task[]; -} -export declare class Queue { - /** - * @type Task[] - */ - queue: Task[]; - concurrency: number; - total: number; - done: number; - running: number; - finalTask?: () => void; - onError?: (e: Error) => void; - constructor(concurrency: number, config?: Partial); - static of(concurrency?: number, config?: TaskQueueConfig): Queue; - static Promise(concurrency: number, config: { - queue: Task[]; - }): Promise; - pushTask(task: Task): void; - next(): void; - isDone(): boolean; - /** - * 等待队列完成 - */ - allDone(): Promise; -} -export {}; diff --git a/lib/index.esm.js b/lib/index.esm.js deleted file mode 100644 index 695b7e7..0000000 --- a/lib/index.esm.js +++ /dev/null @@ -1,74 +0,0 @@ -function callHook(hook, ...args) { - if (hook) { - return hook(...args); - } -} - -class Queue { - constructor(concurrency, config = {}) { - this.total = 0; - this.done = 0; - this.running = 0; - this.concurrency = concurrency; - this.queue = config.queue || []; - this.finalTask = config.finalTask; - this.total += this.queue.length; - this.onError = config.onError; - return this; - } - static of(concurrency = 1, config) { - return new Queue(concurrency, config); - } - static Promise(concurrency, config) { - return new Promise((resolve, reject) => { - if (!config.queue.length) { - resolve(); - return; - } - const t = Queue.of(concurrency, Object.assign({ onError: reject, finalTask: resolve }, config)); - t.next(); - }); - } - pushTask(task) { - this.total++; - this.queue.push(task); - this.next(); - } - next() { - while (this.running < this.concurrency && this.queue.length) { - const task = this.queue.shift(); - task() - .then(() => { - this.running--; - this.done++; - this.next(); - if (this.isDone()) { - callHook(this.finalTask); - } - }) - .catch((err) => { - callHook(this.onError, err); - }); - this.running++; - } - } - isDone() { - return this.running === 0 && this.queue.length === 0; - } - /** - * 等待队列完成 - */ - allDone() { - return new Promise((resolve, reject) => { - if (this.isDone()) { - return resolve(); - } - else { - this.finalTask = resolve; - this.onError = reject; - } - }); - } -} - -export { Queue }; diff --git a/lib/utils.d.ts b/lib/utils.d.ts deleted file mode 100644 index d9cab33..0000000 --- a/lib/utils.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function callHook(hook: Function | undefined, ...args: any[]): any;