@dropthis/cli 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -0
- package/dist/cli.cjs +1489 -0
- package/dist/cli.cjs.map +1 -0
- package/node_modules/@dropthis/node/README.md +90 -0
- package/node_modules/@dropthis/node/dist/index.cjs +1010 -0
- package/node_modules/@dropthis/node/dist/index.cjs.map +1 -0
- package/node_modules/@dropthis/node/dist/index.d.cts +408 -0
- package/node_modules/@dropthis/node/dist/index.d.ts +408 -0
- package/node_modules/@dropthis/node/dist/index.mjs +969 -0
- package/node_modules/@dropthis/node/dist/index.mjs.map +1 -0
- package/node_modules/@dropthis/node/package.json +55 -0
- package/node_modules/@nodelib/fs.scandir/LICENSE +21 -0
- package/node_modules/@nodelib/fs.scandir/README.md +171 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/adapters/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.d.ts +4 -0
- package/node_modules/@nodelib/fs.scandir/out/constants.js +17 -0
- package/node_modules/@nodelib/fs.scandir/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.scandir/out/index.js +26 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/async.js +104 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.d.ts +1 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/common.js +13 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.d.ts +5 -0
- package/node_modules/@nodelib/fs.scandir/out/providers/sync.js +54 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/settings.js +24 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
- package/node_modules/@nodelib/fs.scandir/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/fs.js +19 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.d.ts +2 -0
- package/node_modules/@nodelib/fs.scandir/out/utils/index.js +5 -0
- package/node_modules/@nodelib/fs.scandir/package.json +44 -0
- package/node_modules/@nodelib/fs.stat/LICENSE +21 -0
- package/node_modules/@nodelib/fs.stat/README.md +126 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
- package/node_modules/@nodelib/fs.stat/out/adapters/fs.js +17 -0
- package/node_modules/@nodelib/fs.stat/out/index.d.ts +12 -0
- package/node_modules/@nodelib/fs.stat/out/index.js +26 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/providers/async.js +36 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.d.ts +3 -0
- package/node_modules/@nodelib/fs.stat/out/providers/sync.js +23 -0
- package/node_modules/@nodelib/fs.stat/out/settings.d.ts +16 -0
- package/node_modules/@nodelib/fs.stat/out/settings.js +16 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.stat/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.stat/package.json +37 -0
- package/node_modules/@nodelib/fs.walk/LICENSE +21 -0
- package/node_modules/@nodelib/fs.walk/README.md +215 -0
- package/node_modules/@nodelib/fs.walk/out/index.d.ts +14 -0
- package/node_modules/@nodelib/fs.walk/out/index.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/async.js +30 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.d.ts +4 -0
- package/node_modules/@nodelib/fs.walk/out/providers/index.js +9 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.d.ts +12 -0
- package/node_modules/@nodelib/fs.walk/out/providers/stream.js +34 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.d.ts +10 -0
- package/node_modules/@nodelib/fs.walk/out/providers/sync.js +14 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/readers/async.js +97 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.d.ts +7 -0
- package/node_modules/@nodelib/fs.walk/out/readers/common.js +31 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
- package/node_modules/@nodelib/fs.walk/out/readers/reader.js +11 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.d.ts +15 -0
- package/node_modules/@nodelib/fs.walk/out/readers/sync.js +59 -0
- package/node_modules/@nodelib/fs.walk/out/settings.d.ts +30 -0
- package/node_modules/@nodelib/fs.walk/out/settings.js +26 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.d.ts +8 -0
- package/node_modules/@nodelib/fs.walk/out/types/index.js +2 -0
- package/node_modules/@nodelib/fs.walk/package.json +44 -0
- package/node_modules/braces/LICENSE +21 -0
- package/node_modules/braces/README.md +586 -0
- package/node_modules/braces/index.js +170 -0
- package/node_modules/braces/lib/compile.js +60 -0
- package/node_modules/braces/lib/constants.js +57 -0
- package/node_modules/braces/lib/expand.js +113 -0
- package/node_modules/braces/lib/parse.js +331 -0
- package/node_modules/braces/lib/stringify.js +32 -0
- package/node_modules/braces/lib/utils.js +122 -0
- package/node_modules/braces/package.json +77 -0
- package/node_modules/fast-glob/LICENSE +21 -0
- package/node_modules/fast-glob/README.md +830 -0
- package/node_modules/fast-glob/out/index.d.ts +40 -0
- package/node_modules/fast-glob/out/index.js +102 -0
- package/node_modules/fast-glob/out/managers/tasks.d.ts +22 -0
- package/node_modules/fast-glob/out/managers/tasks.js +110 -0
- package/node_modules/fast-glob/out/providers/async.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/async.js +23 -0
- package/node_modules/fast-glob/out/providers/filters/deep.d.ts +16 -0
- package/node_modules/fast-glob/out/providers/filters/deep.js +62 -0
- package/node_modules/fast-glob/out/providers/filters/entry.d.ts +17 -0
- package/node_modules/fast-glob/out/providers/filters/entry.js +85 -0
- package/node_modules/fast-glob/out/providers/filters/error.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/filters/error.js +15 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.d.ts +33 -0
- package/node_modules/fast-glob/out/providers/matchers/matcher.js +45 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.d.ts +4 -0
- package/node_modules/fast-glob/out/providers/matchers/partial.js +38 -0
- package/node_modules/fast-glob/out/providers/provider.d.ts +19 -0
- package/node_modules/fast-glob/out/providers/provider.js +48 -0
- package/node_modules/fast-glob/out/providers/stream.d.ts +11 -0
- package/node_modules/fast-glob/out/providers/stream.js +31 -0
- package/node_modules/fast-glob/out/providers/sync.d.ts +9 -0
- package/node_modules/fast-glob/out/providers/sync.js +23 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.d.ts +8 -0
- package/node_modules/fast-glob/out/providers/transformers/entry.js +26 -0
- package/node_modules/fast-glob/out/readers/async.d.ts +10 -0
- package/node_modules/fast-glob/out/readers/async.js +35 -0
- package/node_modules/fast-glob/out/readers/reader.d.ts +15 -0
- package/node_modules/fast-glob/out/readers/reader.js +33 -0
- package/node_modules/fast-glob/out/readers/stream.d.ts +14 -0
- package/node_modules/fast-glob/out/readers/stream.js +55 -0
- package/node_modules/fast-glob/out/readers/sync.d.ts +12 -0
- package/node_modules/fast-glob/out/readers/sync.js +43 -0
- package/node_modules/fast-glob/out/settings.d.ts +164 -0
- package/node_modules/fast-glob/out/settings.js +59 -0
- package/node_modules/fast-glob/out/types/index.d.ts +31 -0
- package/node_modules/fast-glob/out/types/index.js +2 -0
- package/node_modules/fast-glob/out/utils/array.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/array.js +22 -0
- package/node_modules/fast-glob/out/utils/errno.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/errno.js +7 -0
- package/node_modules/fast-glob/out/utils/fs.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/fs.js +19 -0
- package/node_modules/fast-glob/out/utils/index.d.ts +8 -0
- package/node_modules/fast-glob/out/utils/index.js +17 -0
- package/node_modules/fast-glob/out/utils/path.d.ts +13 -0
- package/node_modules/fast-glob/out/utils/path.js +68 -0
- package/node_modules/fast-glob/out/utils/pattern.d.ts +49 -0
- package/node_modules/fast-glob/out/utils/pattern.js +206 -0
- package/node_modules/fast-glob/out/utils/stream.d.ts +4 -0
- package/node_modules/fast-glob/out/utils/stream.js +17 -0
- package/node_modules/fast-glob/out/utils/string.d.ts +2 -0
- package/node_modules/fast-glob/out/utils/string.js +11 -0
- package/node_modules/fast-glob/package.json +81 -0
- package/node_modules/fastq/LICENSE +13 -0
- package/node_modules/fastq/README.md +310 -0
- package/node_modules/fastq/SECURITY.md +15 -0
- package/node_modules/fastq/bench.js +66 -0
- package/node_modules/fastq/eslint.config.js +11 -0
- package/node_modules/fastq/example.js +14 -0
- package/node_modules/fastq/example.mjs +9 -0
- package/node_modules/fastq/index.d.ts +59 -0
- package/node_modules/fastq/package.json +49 -0
- package/node_modules/fastq/queue.js +346 -0
- package/node_modules/fastq/test/example.ts +83 -0
- package/node_modules/fastq/test/promise.js +325 -0
- package/node_modules/fastq/test/test.js +733 -0
- package/node_modules/fastq/test/tsconfig.json +11 -0
- package/node_modules/fill-range/LICENSE +21 -0
- package/node_modules/fill-range/README.md +237 -0
- package/node_modules/fill-range/index.js +248 -0
- package/node_modules/fill-range/package.json +74 -0
- package/node_modules/glob-parent/LICENSE +15 -0
- package/node_modules/glob-parent/README.md +137 -0
- package/node_modules/glob-parent/index.js +42 -0
- package/node_modules/glob-parent/package.json +48 -0
- package/node_modules/ignore/LICENSE-MIT +21 -0
- package/node_modules/ignore/README.md +452 -0
- package/node_modules/ignore/index.d.ts +81 -0
- package/node_modules/ignore/index.js +784 -0
- package/node_modules/ignore/legacy.js +681 -0
- package/node_modules/ignore/package.json +87 -0
- package/node_modules/is-extglob/LICENSE +21 -0
- package/node_modules/is-extglob/README.md +107 -0
- package/node_modules/is-extglob/index.js +20 -0
- package/node_modules/is-extglob/package.json +69 -0
- package/node_modules/is-glob/LICENSE +21 -0
- package/node_modules/is-glob/README.md +206 -0
- package/node_modules/is-glob/index.js +150 -0
- package/node_modules/is-glob/package.json +81 -0
- package/node_modules/is-number/LICENSE +21 -0
- package/node_modules/is-number/README.md +187 -0
- package/node_modules/is-number/index.js +18 -0
- package/node_modules/is-number/package.json +82 -0
- package/node_modules/merge2/LICENSE +21 -0
- package/node_modules/merge2/README.md +144 -0
- package/node_modules/merge2/index.js +144 -0
- package/node_modules/merge2/package.json +43 -0
- package/node_modules/micromatch/LICENSE +21 -0
- package/node_modules/micromatch/README.md +1024 -0
- package/node_modules/micromatch/index.js +474 -0
- package/node_modules/micromatch/package.json +119 -0
- package/node_modules/mime-db/HISTORY.md +541 -0
- package/node_modules/mime-db/LICENSE +23 -0
- package/node_modules/mime-db/README.md +109 -0
- package/node_modules/mime-db/db.json +9342 -0
- package/node_modules/mime-db/index.js +12 -0
- package/node_modules/mime-db/package.json +56 -0
- package/node_modules/mime-types/HISTORY.md +421 -0
- package/node_modules/mime-types/LICENSE +23 -0
- package/node_modules/mime-types/README.md +126 -0
- package/node_modules/mime-types/index.js +211 -0
- package/node_modules/mime-types/mimeScore.js +52 -0
- package/node_modules/mime-types/package.json +45 -0
- package/node_modules/picomatch/LICENSE +21 -0
- package/node_modules/picomatch/README.md +716 -0
- package/node_modules/picomatch/index.js +3 -0
- package/node_modules/picomatch/lib/constants.js +184 -0
- package/node_modules/picomatch/lib/parse.js +1392 -0
- package/node_modules/picomatch/lib/picomatch.js +342 -0
- package/node_modules/picomatch/lib/scan.js +391 -0
- package/node_modules/picomatch/lib/utils.js +64 -0
- package/node_modules/picomatch/package.json +81 -0
- package/node_modules/queue-microtask/LICENSE +20 -0
- package/node_modules/queue-microtask/README.md +90 -0
- package/node_modules/queue-microtask/index.d.ts +2 -0
- package/node_modules/queue-microtask/index.js +9 -0
- package/node_modules/queue-microtask/package.json +55 -0
- package/node_modules/reusify/.github/dependabot.yml +7 -0
- package/node_modules/reusify/.github/workflows/ci.yml +96 -0
- package/node_modules/reusify/LICENSE +22 -0
- package/node_modules/reusify/README.md +139 -0
- package/node_modules/reusify/SECURITY.md +15 -0
- package/node_modules/reusify/benchmarks/createNoCodeFunction.js +30 -0
- package/node_modules/reusify/benchmarks/fib.js +13 -0
- package/node_modules/reusify/benchmarks/reuseNoCodeFunction.js +38 -0
- package/node_modules/reusify/eslint.config.js +14 -0
- package/node_modules/reusify/package.json +50 -0
- package/node_modules/reusify/reusify.d.ts +14 -0
- package/node_modules/reusify/reusify.js +33 -0
- package/node_modules/reusify/test.js +66 -0
- package/node_modules/reusify/tsconfig.json +11 -0
- package/node_modules/run-parallel/LICENSE +20 -0
- package/node_modules/run-parallel/README.md +85 -0
- package/node_modules/run-parallel/index.js +51 -0
- package/node_modules/run-parallel/package.json +58 -0
- package/node_modules/to-regex-range/LICENSE +21 -0
- package/node_modules/to-regex-range/README.md +305 -0
- package/node_modules/to-regex-range/index.js +288 -0
- package/node_modules/to-regex-range/package.json +88 -0
- package/package.json +53 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-var */
|
|
4
|
+
|
|
5
|
+
var reusify = require('reusify')
|
|
6
|
+
|
|
7
|
+
function fastqueue (context, worker, _concurrency) {
|
|
8
|
+
if (typeof context === 'function') {
|
|
9
|
+
_concurrency = worker
|
|
10
|
+
worker = context
|
|
11
|
+
context = null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!(_concurrency >= 1)) {
|
|
15
|
+
throw new Error('fastqueue concurrency must be equal to or greater than 1')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var cache = reusify(Task)
|
|
19
|
+
var queueHead = null
|
|
20
|
+
var queueTail = null
|
|
21
|
+
var _running = 0
|
|
22
|
+
var errorHandler = null
|
|
23
|
+
|
|
24
|
+
var self = {
|
|
25
|
+
push: push,
|
|
26
|
+
drain: noop,
|
|
27
|
+
saturated: noop,
|
|
28
|
+
pause: pause,
|
|
29
|
+
paused: false,
|
|
30
|
+
|
|
31
|
+
get concurrency () {
|
|
32
|
+
return _concurrency
|
|
33
|
+
},
|
|
34
|
+
set concurrency (value) {
|
|
35
|
+
if (!(value >= 1)) {
|
|
36
|
+
throw new Error('fastqueue concurrency must be equal to or greater than 1')
|
|
37
|
+
}
|
|
38
|
+
_concurrency = value
|
|
39
|
+
|
|
40
|
+
if (self.paused) return
|
|
41
|
+
for (; queueHead && _running < _concurrency;) {
|
|
42
|
+
_running++
|
|
43
|
+
release()
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
running: running,
|
|
48
|
+
resume: resume,
|
|
49
|
+
idle: idle,
|
|
50
|
+
length: length,
|
|
51
|
+
getQueue: getQueue,
|
|
52
|
+
unshift: unshift,
|
|
53
|
+
empty: noop,
|
|
54
|
+
kill: kill,
|
|
55
|
+
killAndDrain: killAndDrain,
|
|
56
|
+
error: error,
|
|
57
|
+
abort: abort
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return self
|
|
61
|
+
|
|
62
|
+
function running () {
|
|
63
|
+
return _running
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function pause () {
|
|
67
|
+
self.paused = true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function length () {
|
|
71
|
+
var current = queueHead
|
|
72
|
+
var counter = 0
|
|
73
|
+
|
|
74
|
+
while (current) {
|
|
75
|
+
current = current.next
|
|
76
|
+
counter++
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return counter
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getQueue () {
|
|
83
|
+
var current = queueHead
|
|
84
|
+
var tasks = []
|
|
85
|
+
|
|
86
|
+
while (current) {
|
|
87
|
+
tasks.push(current.value)
|
|
88
|
+
current = current.next
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return tasks
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function resume () {
|
|
95
|
+
if (!self.paused) return
|
|
96
|
+
self.paused = false
|
|
97
|
+
if (queueHead === null) {
|
|
98
|
+
_running++
|
|
99
|
+
release()
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
for (; queueHead && _running < _concurrency;) {
|
|
103
|
+
_running++
|
|
104
|
+
release()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function idle () {
|
|
109
|
+
return _running === 0 && self.length() === 0
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function push (value, done) {
|
|
113
|
+
var current = cache.get()
|
|
114
|
+
|
|
115
|
+
current.context = context
|
|
116
|
+
current.release = release
|
|
117
|
+
current.value = value
|
|
118
|
+
current.callback = done || noop
|
|
119
|
+
current.errorHandler = errorHandler
|
|
120
|
+
|
|
121
|
+
if (_running >= _concurrency || self.paused) {
|
|
122
|
+
if (queueTail) {
|
|
123
|
+
queueTail.next = current
|
|
124
|
+
queueTail = current
|
|
125
|
+
} else {
|
|
126
|
+
queueHead = current
|
|
127
|
+
queueTail = current
|
|
128
|
+
self.saturated()
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
_running++
|
|
132
|
+
worker.call(context, current.value, current.worked)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function unshift (value, done) {
|
|
137
|
+
var current = cache.get()
|
|
138
|
+
|
|
139
|
+
current.context = context
|
|
140
|
+
current.release = release
|
|
141
|
+
current.value = value
|
|
142
|
+
current.callback = done || noop
|
|
143
|
+
current.errorHandler = errorHandler
|
|
144
|
+
|
|
145
|
+
if (_running >= _concurrency || self.paused) {
|
|
146
|
+
if (queueHead) {
|
|
147
|
+
current.next = queueHead
|
|
148
|
+
queueHead = current
|
|
149
|
+
} else {
|
|
150
|
+
queueHead = current
|
|
151
|
+
queueTail = current
|
|
152
|
+
self.saturated()
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
_running++
|
|
156
|
+
worker.call(context, current.value, current.worked)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function release (holder) {
|
|
161
|
+
if (holder) {
|
|
162
|
+
cache.release(holder)
|
|
163
|
+
}
|
|
164
|
+
var next = queueHead
|
|
165
|
+
if (next && _running <= _concurrency) {
|
|
166
|
+
if (!self.paused) {
|
|
167
|
+
if (queueTail === queueHead) {
|
|
168
|
+
queueTail = null
|
|
169
|
+
}
|
|
170
|
+
queueHead = next.next
|
|
171
|
+
next.next = null
|
|
172
|
+
worker.call(context, next.value, next.worked)
|
|
173
|
+
if (queueTail === null) {
|
|
174
|
+
self.empty()
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
_running--
|
|
178
|
+
}
|
|
179
|
+
} else if (--_running === 0) {
|
|
180
|
+
self.drain()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function kill () {
|
|
185
|
+
queueHead = null
|
|
186
|
+
queueTail = null
|
|
187
|
+
self.drain = noop
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function killAndDrain () {
|
|
191
|
+
queueHead = null
|
|
192
|
+
queueTail = null
|
|
193
|
+
self.drain()
|
|
194
|
+
self.drain = noop
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function abort () {
|
|
198
|
+
var current = queueHead
|
|
199
|
+
queueHead = null
|
|
200
|
+
queueTail = null
|
|
201
|
+
|
|
202
|
+
while (current) {
|
|
203
|
+
var next = current.next
|
|
204
|
+
var callback = current.callback
|
|
205
|
+
var errorHandler = current.errorHandler
|
|
206
|
+
var val = current.value
|
|
207
|
+
var context = current.context
|
|
208
|
+
|
|
209
|
+
// Reset the task state
|
|
210
|
+
current.value = null
|
|
211
|
+
current.callback = noop
|
|
212
|
+
current.errorHandler = null
|
|
213
|
+
|
|
214
|
+
// Call error handler if present
|
|
215
|
+
if (errorHandler) {
|
|
216
|
+
errorHandler(new Error('abort'), val)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Call callback with error
|
|
220
|
+
callback.call(context, new Error('abort'))
|
|
221
|
+
|
|
222
|
+
// Release the task back to the pool
|
|
223
|
+
current.release(current)
|
|
224
|
+
|
|
225
|
+
current = next
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
self.drain = noop
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function error (handler) {
|
|
232
|
+
errorHandler = handler
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function noop () {}
|
|
237
|
+
|
|
238
|
+
function Task () {
|
|
239
|
+
this.value = null
|
|
240
|
+
this.callback = noop
|
|
241
|
+
this.next = null
|
|
242
|
+
this.release = noop
|
|
243
|
+
this.context = null
|
|
244
|
+
this.errorHandler = null
|
|
245
|
+
|
|
246
|
+
var self = this
|
|
247
|
+
|
|
248
|
+
this.worked = function worked (err, result) {
|
|
249
|
+
var callback = self.callback
|
|
250
|
+
var errorHandler = self.errorHandler
|
|
251
|
+
var val = self.value
|
|
252
|
+
self.value = null
|
|
253
|
+
self.callback = noop
|
|
254
|
+
if (self.errorHandler) {
|
|
255
|
+
errorHandler(err, val)
|
|
256
|
+
}
|
|
257
|
+
callback.call(self.context, err, result)
|
|
258
|
+
self.release(self)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function queueAsPromised (context, worker, _concurrency) {
|
|
263
|
+
if (typeof context === 'function') {
|
|
264
|
+
_concurrency = worker
|
|
265
|
+
worker = context
|
|
266
|
+
context = null
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function asyncWrapper (arg, cb) {
|
|
270
|
+
worker.call(this, arg)
|
|
271
|
+
.then(function (res) {
|
|
272
|
+
cb(null, res)
|
|
273
|
+
}, cb)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var queue = fastqueue(context, asyncWrapper, _concurrency)
|
|
277
|
+
|
|
278
|
+
var pushCb = queue.push
|
|
279
|
+
var unshiftCb = queue.unshift
|
|
280
|
+
|
|
281
|
+
queue.push = push
|
|
282
|
+
queue.unshift = unshift
|
|
283
|
+
queue.drained = drained
|
|
284
|
+
|
|
285
|
+
return queue
|
|
286
|
+
|
|
287
|
+
function push (value) {
|
|
288
|
+
var p = new Promise(function (resolve, reject) {
|
|
289
|
+
pushCb(value, function (err, result) {
|
|
290
|
+
if (err) {
|
|
291
|
+
reject(err)
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
resolve(result)
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
// Let's fork the promise chain to
|
|
299
|
+
// make the error bubble up to the user but
|
|
300
|
+
// not lead to a unhandledRejection
|
|
301
|
+
p.catch(noop)
|
|
302
|
+
|
|
303
|
+
return p
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function unshift (value) {
|
|
307
|
+
var p = new Promise(function (resolve, reject) {
|
|
308
|
+
unshiftCb(value, function (err, result) {
|
|
309
|
+
if (err) {
|
|
310
|
+
reject(err)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
resolve(result)
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
// Let's fork the promise chain to
|
|
318
|
+
// make the error bubble up to the user but
|
|
319
|
+
// not lead to a unhandledRejection
|
|
320
|
+
p.catch(noop)
|
|
321
|
+
|
|
322
|
+
return p
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function drained () {
|
|
326
|
+
var p = new Promise(function (resolve) {
|
|
327
|
+
process.nextTick(function () {
|
|
328
|
+
if (queue.idle()) {
|
|
329
|
+
resolve()
|
|
330
|
+
} else {
|
|
331
|
+
var previousDrain = queue.drain
|
|
332
|
+
queue.drain = function () {
|
|
333
|
+
if (typeof previousDrain === 'function') previousDrain()
|
|
334
|
+
resolve()
|
|
335
|
+
queue.drain = previousDrain
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
return p
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
module.exports = fastqueue
|
|
346
|
+
module.exports.promise = queueAsPromised
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as fastq from '../'
|
|
2
|
+
import { promise as queueAsPromised } from '../'
|
|
3
|
+
|
|
4
|
+
// Basic example
|
|
5
|
+
|
|
6
|
+
const queue = fastq(worker, 1)
|
|
7
|
+
|
|
8
|
+
queue.push('world', (err, result) => {
|
|
9
|
+
if (err) throw err
|
|
10
|
+
console.log('the result is', result)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
queue.push('push without cb')
|
|
14
|
+
|
|
15
|
+
queue.concurrency
|
|
16
|
+
|
|
17
|
+
queue.drain()
|
|
18
|
+
|
|
19
|
+
queue.empty = () => undefined
|
|
20
|
+
|
|
21
|
+
console.log('the queue tasks are', queue.getQueue())
|
|
22
|
+
|
|
23
|
+
queue.idle()
|
|
24
|
+
|
|
25
|
+
queue.kill()
|
|
26
|
+
|
|
27
|
+
queue.killAndDrain()
|
|
28
|
+
|
|
29
|
+
queue.length
|
|
30
|
+
|
|
31
|
+
queue.pause()
|
|
32
|
+
|
|
33
|
+
queue.resume()
|
|
34
|
+
|
|
35
|
+
queue.running()
|
|
36
|
+
|
|
37
|
+
queue.saturated = () => undefined
|
|
38
|
+
|
|
39
|
+
queue.unshift('world', (err, result) => {
|
|
40
|
+
if (err) throw err
|
|
41
|
+
console.log('the result is', result)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
queue.unshift('unshift without cb')
|
|
45
|
+
|
|
46
|
+
function worker(task: any, cb: fastq.done) {
|
|
47
|
+
cb(null, 'hello ' + task)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Generics example
|
|
51
|
+
|
|
52
|
+
interface GenericsContext {
|
|
53
|
+
base: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1)
|
|
57
|
+
|
|
58
|
+
genericsQueue.push(7, (err, done) => {
|
|
59
|
+
if (err) throw err
|
|
60
|
+
console.log('the result is', done)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
genericsQueue.unshift(7, (err, done) => {
|
|
64
|
+
if (err) throw err
|
|
65
|
+
console.log('the result is', done)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) {
|
|
69
|
+
cb(null, 'the meaning of life is ' + (this.base * task))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const queue2 = queueAsPromised(asyncWorker, 1)
|
|
73
|
+
|
|
74
|
+
async function asyncWorker(task: any) {
|
|
75
|
+
return 'hello ' + task
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function run () {
|
|
79
|
+
await queue.push(42)
|
|
80
|
+
await queue.unshift(42)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
run()
|