uneventful 0.0.4 → 0.0.6
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/dist/call-or-wait-DHkBd_bM.mjs +773 -0
- package/dist/call-or-wait-DHkBd_bM.mjs.map +1 -0
- package/dist/mod.d.ts +22 -1575
- package/dist/mod.mjs +8 -1341
- package/dist/mod.mjs.map +1 -1
- package/dist/signals.d.ts +470 -0
- package/dist/signals.mjs +590 -0
- package/dist/signals.mjs.map +1 -0
- package/dist/sinks-kEzJo6Hc.d.ts +182 -0
- package/dist/types-N2ua11te.d.ts +966 -0
- package/dist/utils.d.ts +58 -0
- package/dist/utils.mjs +18 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +25 -8
|
@@ -0,0 +1,773 @@
|
|
|
1
|
+
import { isFunction, apply } from './utils.mjs';
|
|
2
|
+
|
|
3
|
+
let defer = typeof queueMicrotask === "function" ? queueMicrotask : /* @__PURE__ */ ((p) => (cb) => p.then(cb))(Promise.resolve());
|
|
4
|
+
|
|
5
|
+
function resolve(request, val) {
|
|
6
|
+
request("next", val);
|
|
7
|
+
}
|
|
8
|
+
function reject(request, reason) {
|
|
9
|
+
request("throw", void 0, reason);
|
|
10
|
+
}
|
|
11
|
+
function resolver(request) {
|
|
12
|
+
return request.bind(null, "next");
|
|
13
|
+
}
|
|
14
|
+
function rejecter(request) {
|
|
15
|
+
return request.bind(null, "throw", void 0);
|
|
16
|
+
}
|
|
17
|
+
function noop() {
|
|
18
|
+
}
|
|
19
|
+
function mkResult(op, val, err) {
|
|
20
|
+
return { op, val, err };
|
|
21
|
+
}
|
|
22
|
+
const CancelResult = Object.freeze(mkResult("cancel"));
|
|
23
|
+
function ValueResult(val) {
|
|
24
|
+
return mkResult("next", val);
|
|
25
|
+
}
|
|
26
|
+
function ErrorResult(err) {
|
|
27
|
+
return mkResult("throw", void 0, err);
|
|
28
|
+
}
|
|
29
|
+
function isCancel(res) {
|
|
30
|
+
return res === CancelResult;
|
|
31
|
+
}
|
|
32
|
+
function isValue(res) {
|
|
33
|
+
return res ? res.op === "next" : false;
|
|
34
|
+
}
|
|
35
|
+
function isError(res) {
|
|
36
|
+
return res ? res.op === "throw" : false;
|
|
37
|
+
}
|
|
38
|
+
function isUnhandled(res) {
|
|
39
|
+
return isError(res) && res.val === void 0;
|
|
40
|
+
}
|
|
41
|
+
function isHandled(res) {
|
|
42
|
+
return isError(res) && res.val === null;
|
|
43
|
+
}
|
|
44
|
+
function markHandled(res) {
|
|
45
|
+
res.val = null;
|
|
46
|
+
return res.err;
|
|
47
|
+
}
|
|
48
|
+
function getResult(res) {
|
|
49
|
+
if (isValue(res))
|
|
50
|
+
return res.val;
|
|
51
|
+
res.op;
|
|
52
|
+
fulfillPromise(noop, (e) => {
|
|
53
|
+
throw e;
|
|
54
|
+
}, res);
|
|
55
|
+
}
|
|
56
|
+
function fulfillPromise(resolve2, reject2, res) {
|
|
57
|
+
if (isError(res))
|
|
58
|
+
reject2(markHandled(res));
|
|
59
|
+
else if (isCancel(res))
|
|
60
|
+
reject2(new CancelError("Job canceled"));
|
|
61
|
+
else
|
|
62
|
+
resolve2(res.val);
|
|
63
|
+
}
|
|
64
|
+
function propagateResult(job, res) {
|
|
65
|
+
if (!job.result())
|
|
66
|
+
fulfillPromise(job.return.bind(job), job.throw.bind(job), res);
|
|
67
|
+
}
|
|
68
|
+
class CancelError extends Error {
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var current = makeCtx();
|
|
72
|
+
function swapCtx(future) {
|
|
73
|
+
const now = current;
|
|
74
|
+
current = future;
|
|
75
|
+
return now;
|
|
76
|
+
}
|
|
77
|
+
var freelist = [];
|
|
78
|
+
function makeCtx(job, cell) {
|
|
79
|
+
if (freelist && freelist.length) {
|
|
80
|
+
const s = freelist.pop();
|
|
81
|
+
s.job = job;
|
|
82
|
+
s.cell = cell;
|
|
83
|
+
return s;
|
|
84
|
+
}
|
|
85
|
+
return { job, cell };
|
|
86
|
+
}
|
|
87
|
+
function freeCtx(s) {
|
|
88
|
+
s.job = s.cell = null;
|
|
89
|
+
freelist.push(s);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const catchers = /* @__PURE__ */ new WeakMap(), defaultCatch = (e) => {
|
|
93
|
+
Promise.reject(e);
|
|
94
|
+
};
|
|
95
|
+
const nullCtx = makeCtx();
|
|
96
|
+
const owners = /* @__PURE__ */ new WeakMap();
|
|
97
|
+
|
|
98
|
+
function chain() {
|
|
99
|
+
return link(0, void 0, void 0);
|
|
100
|
+
}
|
|
101
|
+
function recycle(c) {
|
|
102
|
+
while (c.v)
|
|
103
|
+
unlink(c, c.n);
|
|
104
|
+
c.u = void 0;
|
|
105
|
+
unlink(c, c);
|
|
106
|
+
}
|
|
107
|
+
function unshift(c, v) {
|
|
108
|
+
++c.v;
|
|
109
|
+
link(v, c.n, c);
|
|
110
|
+
}
|
|
111
|
+
function push(c, v) {
|
|
112
|
+
++c.v;
|
|
113
|
+
link(v, c, c.p);
|
|
114
|
+
}
|
|
115
|
+
function pushCB(c, v) {
|
|
116
|
+
++c.v;
|
|
117
|
+
return unlinker(c, link(v, c, c.p));
|
|
118
|
+
}
|
|
119
|
+
function isEmpty(c) {
|
|
120
|
+
return !c || c.v === 0;
|
|
121
|
+
}
|
|
122
|
+
function qlen(c) {
|
|
123
|
+
return c ? c.v : 0;
|
|
124
|
+
}
|
|
125
|
+
function pop(c) {
|
|
126
|
+
if (qlen(c))
|
|
127
|
+
return unlink(c, c.p);
|
|
128
|
+
}
|
|
129
|
+
class Node {
|
|
130
|
+
constructor() {
|
|
131
|
+
/** The next node (or the start node if this is a chain head) */
|
|
132
|
+
this.n = this;
|
|
133
|
+
/** The previous node (or the end node if this is a chain head) */
|
|
134
|
+
this.p = this;
|
|
135
|
+
/** The value held by the node (or the chain length if this is a chain head) */
|
|
136
|
+
this.v = void 0;
|
|
137
|
+
/** The most recently created undo callback for this node */
|
|
138
|
+
this.u = void 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
var free;
|
|
142
|
+
function link(v, n, p) {
|
|
143
|
+
let node = free;
|
|
144
|
+
if (node) {
|
|
145
|
+
free = node.n;
|
|
146
|
+
node.n = n || node;
|
|
147
|
+
node.p = p || node;
|
|
148
|
+
} else {
|
|
149
|
+
node = new Node();
|
|
150
|
+
if (n)
|
|
151
|
+
node.n = n;
|
|
152
|
+
if (p)
|
|
153
|
+
node.p = p;
|
|
154
|
+
}
|
|
155
|
+
node.v = v;
|
|
156
|
+
node.n.p = node;
|
|
157
|
+
node.p.n = node;
|
|
158
|
+
return node;
|
|
159
|
+
}
|
|
160
|
+
function unlink(c, node) {
|
|
161
|
+
--c.v;
|
|
162
|
+
var v = node.v, u = node.u;
|
|
163
|
+
node.n && (node.n.p = node.p);
|
|
164
|
+
node.p && (node.p.n = node.n);
|
|
165
|
+
node.u = node.v = node.p = void 0;
|
|
166
|
+
node.n = free;
|
|
167
|
+
free = node;
|
|
168
|
+
if (u)
|
|
169
|
+
u();
|
|
170
|
+
return v;
|
|
171
|
+
}
|
|
172
|
+
function unlinker(chain2, node) {
|
|
173
|
+
let u = node.u ||= () => {
|
|
174
|
+
if (u) {
|
|
175
|
+
if (u === node.u)
|
|
176
|
+
unlink(chain2, node);
|
|
177
|
+
u = chain2 = node = void 0;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return u;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function getJob() {
|
|
184
|
+
const { job } = current;
|
|
185
|
+
if (job)
|
|
186
|
+
return job;
|
|
187
|
+
throw new Error("No job is currently active");
|
|
188
|
+
}
|
|
189
|
+
function recalcJob(job) {
|
|
190
|
+
return (cb) => {
|
|
191
|
+
current.job.must(job.release(cb));
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function runChain(res, cbs) {
|
|
195
|
+
while (qlen(cbs))
|
|
196
|
+
try {
|
|
197
|
+
pop(cbs)(res);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
detached.asyncThrow(e);
|
|
200
|
+
}
|
|
201
|
+
cbs && recycle(cbs);
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
var inProcess = /* @__PURE__ */ new Set();
|
|
205
|
+
class _Job {
|
|
206
|
+
constructor() {
|
|
207
|
+
this.end = () => {
|
|
208
|
+
const res = this._done ||= CancelResult, cbs = this._cbs;
|
|
209
|
+
if (!cbs && !isUnhandled(res))
|
|
210
|
+
return;
|
|
211
|
+
const ct = inProcess.size, old = swapCtx(nullCtx);
|
|
212
|
+
if (!ct)
|
|
213
|
+
inProcess.add(null);
|
|
214
|
+
if (cbs && cbs.u)
|
|
215
|
+
cbs.u = runChain(res, cbs.u);
|
|
216
|
+
inProcess.add(this);
|
|
217
|
+
if (ct) {
|
|
218
|
+
swapCtx(old);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
inProcess.delete(null);
|
|
222
|
+
for (const item of inProcess) {
|
|
223
|
+
if (item._cbs)
|
|
224
|
+
item._cbs = runChain(item._done, item._cbs);
|
|
225
|
+
inProcess.delete(item);
|
|
226
|
+
if (isUnhandled(item._done))
|
|
227
|
+
item.throw(markHandled(item._done));
|
|
228
|
+
}
|
|
229
|
+
swapCtx(old);
|
|
230
|
+
};
|
|
231
|
+
this._done = void 0;
|
|
232
|
+
// Chain whose .u stores a second chain for `release()` callbacks
|
|
233
|
+
this._cbs = void 0;
|
|
234
|
+
}
|
|
235
|
+
/** @internal */
|
|
236
|
+
static create(parent, stop) {
|
|
237
|
+
const job = new _Job();
|
|
238
|
+
if (parent || stop) {
|
|
239
|
+
job.must((parent ||= getJob()).release(stop || job.end));
|
|
240
|
+
owners.set(job, parent);
|
|
241
|
+
}
|
|
242
|
+
return job;
|
|
243
|
+
}
|
|
244
|
+
do(cleanup) {
|
|
245
|
+
unshift(this._chain(), cleanup);
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
onError(cb) {
|
|
249
|
+
return this.do((r) => {
|
|
250
|
+
if (isError(r))
|
|
251
|
+
cb(markHandled(r));
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
onValue(cb) {
|
|
255
|
+
return this.do((r) => {
|
|
256
|
+
if (isValue(r))
|
|
257
|
+
cb(r.val);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
onCancel(cb) {
|
|
261
|
+
return this.do((r) => {
|
|
262
|
+
if (isCancel(r))
|
|
263
|
+
cb();
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
result() {
|
|
267
|
+
return this._done || current.cell?.recalcWhen(this, recalcJob) || void 0;
|
|
268
|
+
}
|
|
269
|
+
get [Symbol.toStringTag]() {
|
|
270
|
+
return "Job";
|
|
271
|
+
}
|
|
272
|
+
restart() {
|
|
273
|
+
if (!this._done && inProcess.size) {
|
|
274
|
+
const old = inProcess;
|
|
275
|
+
inProcess = /* @__PURE__ */ new Set();
|
|
276
|
+
this.end();
|
|
277
|
+
inProcess = old;
|
|
278
|
+
} else {
|
|
279
|
+
this._end(CancelResult);
|
|
280
|
+
}
|
|
281
|
+
this._done = void 0;
|
|
282
|
+
promises.delete(this);
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
_end(res) {
|
|
286
|
+
if (this._done)
|
|
287
|
+
throw new Error("Job already ended");
|
|
288
|
+
if (this !== detached)
|
|
289
|
+
this._done = res;
|
|
290
|
+
this.end();
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
throw(err) {
|
|
294
|
+
if (this._done) {
|
|
295
|
+
(owners.get(this) || detached).asyncThrow(err);
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
return this._end(ErrorResult(err));
|
|
299
|
+
}
|
|
300
|
+
return(val) {
|
|
301
|
+
return this._end(ValueResult(val));
|
|
302
|
+
}
|
|
303
|
+
then(onfulfilled, onrejected) {
|
|
304
|
+
return nativePromise(this).then(onfulfilled, onrejected);
|
|
305
|
+
}
|
|
306
|
+
catch(onrejected) {
|
|
307
|
+
return nativePromise(this).catch(onrejected);
|
|
308
|
+
}
|
|
309
|
+
finally(onfinally) {
|
|
310
|
+
return nativePromise(this).finally(onfinally);
|
|
311
|
+
}
|
|
312
|
+
*[Symbol.iterator]() {
|
|
313
|
+
if (this._done) {
|
|
314
|
+
return getResult(this._done);
|
|
315
|
+
} else
|
|
316
|
+
return yield (req) => {
|
|
317
|
+
this.do((res) => fulfillPromise(resolver(req), rejecter(req), res));
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
start(fnOrCtx, fn) {
|
|
321
|
+
if (!fnOrCtx)
|
|
322
|
+
return makeJob(this);
|
|
323
|
+
let init, result;
|
|
324
|
+
if (isFunction(fn)) {
|
|
325
|
+
init = fn.bind(fnOrCtx);
|
|
326
|
+
} else if (isFunction(fnOrCtx)) {
|
|
327
|
+
init = fnOrCtx;
|
|
328
|
+
} else if (fnOrCtx instanceof _Job) {
|
|
329
|
+
return fnOrCtx;
|
|
330
|
+
} else {
|
|
331
|
+
result = fnOrCtx;
|
|
332
|
+
}
|
|
333
|
+
const job = makeJob(this);
|
|
334
|
+
try {
|
|
335
|
+
if (init)
|
|
336
|
+
result = job.run(init, job);
|
|
337
|
+
if (result != null) {
|
|
338
|
+
if (result instanceof _Job) {
|
|
339
|
+
if (result !== job)
|
|
340
|
+
result.do((res) => propagateResult(job, res));
|
|
341
|
+
} else if (isFunction(result.then)) {
|
|
342
|
+
result.then(
|
|
343
|
+
(v) => {
|
|
344
|
+
job.result() || job.return(v);
|
|
345
|
+
},
|
|
346
|
+
(e) => {
|
|
347
|
+
job.result() || job.throw(e);
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
return job;
|
|
351
|
+
} else if (isFunction(result[Symbol.iterator]) && typeof result !== "string") {
|
|
352
|
+
job.run(runGen, result, job);
|
|
353
|
+
} else if (isFunction(result)) {
|
|
354
|
+
job.must(result);
|
|
355
|
+
} else {
|
|
356
|
+
throw new TypeError("Invalid value/return for start()");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return job;
|
|
360
|
+
} catch (e) {
|
|
361
|
+
job.end();
|
|
362
|
+
throw e;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
connect(src, sink, inlet) {
|
|
366
|
+
return this.start((job) => void src(sink, job, inlet));
|
|
367
|
+
}
|
|
368
|
+
run(fn, ...args) {
|
|
369
|
+
const old = swapCtx(makeCtx(this));
|
|
370
|
+
try {
|
|
371
|
+
return fn(...args);
|
|
372
|
+
} finally {
|
|
373
|
+
freeCtx(swapCtx(old));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
bind(fn) {
|
|
377
|
+
const job = this;
|
|
378
|
+
return function() {
|
|
379
|
+
const old = swapCtx(makeCtx(job));
|
|
380
|
+
try {
|
|
381
|
+
return apply(fn, this, arguments);
|
|
382
|
+
} finally {
|
|
383
|
+
freeCtx(swapCtx(old));
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
must(cleanup) {
|
|
388
|
+
if (isFunction(cleanup))
|
|
389
|
+
push(this._chain(), cleanup);
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
release(cleanup) {
|
|
393
|
+
if (this === detached)
|
|
394
|
+
return noop;
|
|
395
|
+
let cbs = this._chain();
|
|
396
|
+
if (!this._done || cbs.u)
|
|
397
|
+
cbs = cbs.u ||= chain();
|
|
398
|
+
return pushCB(cbs, cleanup);
|
|
399
|
+
}
|
|
400
|
+
asyncThrow(err) {
|
|
401
|
+
try {
|
|
402
|
+
(catchers.get(this) || this.throw).call(this, err);
|
|
403
|
+
} catch (e) {
|
|
404
|
+
if (this === detached)
|
|
405
|
+
catchers.set(this, defaultCatch);
|
|
406
|
+
else
|
|
407
|
+
catchers.delete(this);
|
|
408
|
+
const catcher = catchers.get(this) || this.throw;
|
|
409
|
+
catcher.call(this, err);
|
|
410
|
+
catcher.call(this, e);
|
|
411
|
+
}
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
asyncCatch(handler) {
|
|
415
|
+
if (isFunction(handler))
|
|
416
|
+
catchers.set(this, handler);
|
|
417
|
+
else if (handler === null)
|
|
418
|
+
catchers.delete(this);
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
_chain() {
|
|
422
|
+
if (this === detached)
|
|
423
|
+
this.end();
|
|
424
|
+
if (this._done && isEmpty(this._cbs))
|
|
425
|
+
defer(this.end);
|
|
426
|
+
return this._cbs ||= chain();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const promises = /* @__PURE__ */ new WeakMap();
|
|
430
|
+
function nativePromise(job) {
|
|
431
|
+
if (!promises.has(job)) {
|
|
432
|
+
promises.set(job, new Promise((res, rej) => {
|
|
433
|
+
const toPromise = fulfillPromise.bind(null, res, rej);
|
|
434
|
+
if (job.result())
|
|
435
|
+
toPromise(job.result());
|
|
436
|
+
else
|
|
437
|
+
job.do(toPromise);
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
440
|
+
return promises.get(job);
|
|
441
|
+
}
|
|
442
|
+
const makeJob = _Job.create;
|
|
443
|
+
const detached = makeJob();
|
|
444
|
+
detached.end = () => {
|
|
445
|
+
throw new Error("Can't do that with the detached job");
|
|
446
|
+
};
|
|
447
|
+
detached.asyncCatch(defaultCatch);
|
|
448
|
+
function runGen(g, job) {
|
|
449
|
+
let it = g[Symbol.iterator](), running = true, ctx = makeCtx(job), ct = 0;
|
|
450
|
+
let done = ctx.job.release(() => {
|
|
451
|
+
job = void 0;
|
|
452
|
+
++ct;
|
|
453
|
+
step("return", void 0);
|
|
454
|
+
});
|
|
455
|
+
defer(() => {
|
|
456
|
+
running = false;
|
|
457
|
+
step("next", void 0);
|
|
458
|
+
});
|
|
459
|
+
function step(method, arg) {
|
|
460
|
+
if (!it)
|
|
461
|
+
return;
|
|
462
|
+
if (running) {
|
|
463
|
+
return defer(step.bind(null, method, arg));
|
|
464
|
+
}
|
|
465
|
+
const old = swapCtx(ctx);
|
|
466
|
+
try {
|
|
467
|
+
running = true;
|
|
468
|
+
try {
|
|
469
|
+
for (; ; ) {
|
|
470
|
+
++ct;
|
|
471
|
+
const { done: done2, value } = it[method](arg);
|
|
472
|
+
if (done2) {
|
|
473
|
+
job && job.return(value);
|
|
474
|
+
job = void 0;
|
|
475
|
+
break;
|
|
476
|
+
} else if (!isFunction(value)) {
|
|
477
|
+
method = "throw";
|
|
478
|
+
arg = new TypeError("Jobs must yield functions (or yield* Yielding<T>s)");
|
|
479
|
+
continue;
|
|
480
|
+
} else {
|
|
481
|
+
let called = false, returned = false, count = ct;
|
|
482
|
+
value((op, val, err) => {
|
|
483
|
+
if (called)
|
|
484
|
+
return;
|
|
485
|
+
else
|
|
486
|
+
called = true;
|
|
487
|
+
method = op;
|
|
488
|
+
arg = op === "next" ? val : err;
|
|
489
|
+
if (returned && count === ct)
|
|
490
|
+
step(op, arg);
|
|
491
|
+
});
|
|
492
|
+
returned = true;
|
|
493
|
+
if (!called)
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
} catch (e) {
|
|
498
|
+
it = job = void 0;
|
|
499
|
+
ctx.job.throw(e);
|
|
500
|
+
}
|
|
501
|
+
it = void 0;
|
|
502
|
+
done?.();
|
|
503
|
+
done = void 0;
|
|
504
|
+
} finally {
|
|
505
|
+
swapCtx(old);
|
|
506
|
+
running = false;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
class RunQueue {
|
|
512
|
+
constructor(sched, reap) {
|
|
513
|
+
this.sched = sched;
|
|
514
|
+
this.reap = reap;
|
|
515
|
+
this._flags = 0 /* Unset */;
|
|
516
|
+
this.q = /* @__PURE__ */ new Set();
|
|
517
|
+
this._run = () => {
|
|
518
|
+
this._flags &= ~2 /* Scheduled */;
|
|
519
|
+
this.flush();
|
|
520
|
+
};
|
|
521
|
+
/** Run all pending items */
|
|
522
|
+
this.flush = () => {
|
|
523
|
+
if (this._flags & 1 /* Running */)
|
|
524
|
+
return;
|
|
525
|
+
const { q: queue } = this;
|
|
526
|
+
if (!queue.size)
|
|
527
|
+
return;
|
|
528
|
+
this._flags |= 1 /* Running */;
|
|
529
|
+
try {
|
|
530
|
+
this.reap(queue);
|
|
531
|
+
} finally {
|
|
532
|
+
this._flags &= ~1 /* Running */;
|
|
533
|
+
!queue.size || this._flags & 2 /* Scheduled */ || this._sched();
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/** Is this queue currently running? */
|
|
538
|
+
isRunning() {
|
|
539
|
+
return !!(this._flags & 1 /* Running */);
|
|
540
|
+
}
|
|
541
|
+
/** Is this queue currently empty? */
|
|
542
|
+
isEmpty() {
|
|
543
|
+
return !this.q.size;
|
|
544
|
+
}
|
|
545
|
+
add(subject) {
|
|
546
|
+
this.q.size || this._flags & (1 /* Running */ | 2 /* Scheduled */) || this._sched();
|
|
547
|
+
this.q.add(subject);
|
|
548
|
+
}
|
|
549
|
+
delete(subject) {
|
|
550
|
+
this.q.delete(subject);
|
|
551
|
+
}
|
|
552
|
+
has(subject) {
|
|
553
|
+
return this.q.has(subject);
|
|
554
|
+
}
|
|
555
|
+
_sched() {
|
|
556
|
+
this._flags |= 2 /* Scheduled */;
|
|
557
|
+
this.sched(this._run);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
var currentRule;
|
|
561
|
+
var currentQueue;
|
|
562
|
+
const ruleQueues = /* @__PURE__ */ new WeakMap();
|
|
563
|
+
const ruleStops = /* @__PURE__ */ new WeakMap();
|
|
564
|
+
class RuleQueue extends RunQueue {
|
|
565
|
+
constructor(sched) {
|
|
566
|
+
super(sched, function(q) {
|
|
567
|
+
if (currentQueue)
|
|
568
|
+
return;
|
|
569
|
+
currentQueue = this;
|
|
570
|
+
try {
|
|
571
|
+
for (currentRule of q) {
|
|
572
|
+
currentRule.catchUp();
|
|
573
|
+
q.delete(currentRule);
|
|
574
|
+
}
|
|
575
|
+
} finally {
|
|
576
|
+
currentQueue = currentRule = void 0;
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function ruleQueue(scheduleFn = defer) {
|
|
582
|
+
ruleQueues.has(scheduleFn) || ruleQueues.set(scheduleFn, new RuleQueue(scheduleFn));
|
|
583
|
+
return ruleQueues.get(scheduleFn);
|
|
584
|
+
}
|
|
585
|
+
const defaultQ = /* @__PURE__ */ ruleQueue(defer);
|
|
586
|
+
const pulls = /* @__PURE__ */ new RunQueue(defer, (pulls2) => {
|
|
587
|
+
for (const conn of pulls2) {
|
|
588
|
+
pulls2.delete(conn);
|
|
589
|
+
conn.doPull();
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
function backpressure(inlet = defaultInlet) {
|
|
594
|
+
const job = getJob();
|
|
595
|
+
return (cb) => {
|
|
596
|
+
if (!job.result() && inlet.isOpen()) {
|
|
597
|
+
if (cb)
|
|
598
|
+
inlet.onReady(cb, job);
|
|
599
|
+
return inlet.isReady();
|
|
600
|
+
}
|
|
601
|
+
return false;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
const IsStream = "uneventful/is-stream";
|
|
605
|
+
function connect(src, sink, inlet) {
|
|
606
|
+
return getJob().connect(src, sink, inlet);
|
|
607
|
+
}
|
|
608
|
+
function throttle(job = current.job) {
|
|
609
|
+
return new _Throttle(job);
|
|
610
|
+
}
|
|
611
|
+
class _Throttle {
|
|
612
|
+
/** @internal */
|
|
613
|
+
constructor(_job) {
|
|
614
|
+
this._job = _job;
|
|
615
|
+
/** @internal */
|
|
616
|
+
this._callbacks = void 0;
|
|
617
|
+
this._isReady = true;
|
|
618
|
+
this._isPulling = false;
|
|
619
|
+
}
|
|
620
|
+
isOpen() {
|
|
621
|
+
return !this._job?.result();
|
|
622
|
+
}
|
|
623
|
+
/** Is the connection ready to receive data? */
|
|
624
|
+
isReady() {
|
|
625
|
+
return this.isOpen() && this._isReady;
|
|
626
|
+
}
|
|
627
|
+
onReady(cb, job) {
|
|
628
|
+
if (!this.isOpen())
|
|
629
|
+
return this;
|
|
630
|
+
const _callbacks = this._callbacks ||= /* @__PURE__ */ new Map();
|
|
631
|
+
const unlink = job.release(() => _callbacks.delete(cb));
|
|
632
|
+
if (this.isReady() && this && !_callbacks.size) {
|
|
633
|
+
pulls.add(this);
|
|
634
|
+
}
|
|
635
|
+
_callbacks.set(cb, unlink);
|
|
636
|
+
return this;
|
|
637
|
+
}
|
|
638
|
+
pause() {
|
|
639
|
+
this._isReady = false;
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
doPull() {
|
|
643
|
+
if (this._isPulling)
|
|
644
|
+
return;
|
|
645
|
+
const { _callbacks } = this;
|
|
646
|
+
if (!_callbacks?.size)
|
|
647
|
+
return;
|
|
648
|
+
this._isPulling = true;
|
|
649
|
+
try {
|
|
650
|
+
for (let [cb, unlink] of _callbacks) {
|
|
651
|
+
if (!this.isReady())
|
|
652
|
+
break;
|
|
653
|
+
unlink();
|
|
654
|
+
_callbacks.delete(cb);
|
|
655
|
+
cb();
|
|
656
|
+
}
|
|
657
|
+
} finally {
|
|
658
|
+
this._isPulling = false;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
resume() {
|
|
662
|
+
if (this.isOpen()) {
|
|
663
|
+
this._isReady = true;
|
|
664
|
+
this.doPull();
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const defaultInlet = throttle();
|
|
669
|
+
function pipe() {
|
|
670
|
+
var v = arguments[0];
|
|
671
|
+
for (var i = 1; i < arguments.length; i++)
|
|
672
|
+
v = arguments[i](v);
|
|
673
|
+
return v;
|
|
674
|
+
}
|
|
675
|
+
function compose(...fns) {
|
|
676
|
+
return (val) => pipe(val, ...fns);
|
|
677
|
+
}
|
|
678
|
+
function into(...args) {
|
|
679
|
+
return (src) => src(...args);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function must(cleanup) {
|
|
683
|
+
getJob().must(cleanup);
|
|
684
|
+
}
|
|
685
|
+
function start(init, fn) {
|
|
686
|
+
return getJob().start(init, fn);
|
|
687
|
+
}
|
|
688
|
+
function isJobActive() {
|
|
689
|
+
return !!current.job;
|
|
690
|
+
}
|
|
691
|
+
const timers = /* @__PURE__ */ new WeakMap();
|
|
692
|
+
function timeout(ms = 0, job = getJob()) {
|
|
693
|
+
let timer = timers.get(job);
|
|
694
|
+
if (timer) {
|
|
695
|
+
clearTimeout(timer);
|
|
696
|
+
} else if (timer === void 0 && !job.result()) {
|
|
697
|
+
job.must(timeout.bind(null, 0, job));
|
|
698
|
+
}
|
|
699
|
+
if (job.result()) {
|
|
700
|
+
timers.delete(job);
|
|
701
|
+
} else if (ms) {
|
|
702
|
+
timers.set(job, setTimeout(() => {
|
|
703
|
+
timers.set(job, null);
|
|
704
|
+
job.end();
|
|
705
|
+
}, ms));
|
|
706
|
+
} else {
|
|
707
|
+
timers.set(job, null);
|
|
708
|
+
}
|
|
709
|
+
return job;
|
|
710
|
+
}
|
|
711
|
+
const abortSignals = /* @__PURE__ */ new WeakMap();
|
|
712
|
+
function abortSignal(job = getJob()) {
|
|
713
|
+
let signal = abortSignals.get(job);
|
|
714
|
+
if (!signal) {
|
|
715
|
+
const ctrl = new AbortController();
|
|
716
|
+
signal = ctrl.signal;
|
|
717
|
+
job.must(() => {
|
|
718
|
+
abortSignals.set(job, null);
|
|
719
|
+
ctrl.abort();
|
|
720
|
+
});
|
|
721
|
+
abortSignals.set(job, signal);
|
|
722
|
+
if (job.result())
|
|
723
|
+
ctrl.abort();
|
|
724
|
+
}
|
|
725
|
+
return signal;
|
|
726
|
+
}
|
|
727
|
+
function restarting(task2) {
|
|
728
|
+
const outer = getJob(), inner = makeJob(outer), { end } = inner;
|
|
729
|
+
task2 ||= (f) => {
|
|
730
|
+
inner.must(f());
|
|
731
|
+
};
|
|
732
|
+
inner.asyncCatch((e) => outer.asyncThrow(e));
|
|
733
|
+
return function() {
|
|
734
|
+
inner.restart().must(outer.release(end));
|
|
735
|
+
const old = swapCtx(makeCtx(inner));
|
|
736
|
+
try {
|
|
737
|
+
return apply(task2, this, arguments);
|
|
738
|
+
} catch (e) {
|
|
739
|
+
inner.restart();
|
|
740
|
+
throw e;
|
|
741
|
+
} finally {
|
|
742
|
+
freeCtx(swapCtx(old));
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function task(fn, _ctx, desc) {
|
|
747
|
+
if (desc)
|
|
748
|
+
return { ...desc, value: task(desc.value) };
|
|
749
|
+
return function(...args) {
|
|
750
|
+
return start(fn.bind(this, ...args));
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function callOrWait(source, method, handler, noArgs) {
|
|
755
|
+
if (source && isFunction(source[method]))
|
|
756
|
+
return source[method]();
|
|
757
|
+
if (isFunction(source))
|
|
758
|
+
return (source.length === 0 ? noArgs(source) : false) || start((job) => {
|
|
759
|
+
connect(source, (v) => handler(job, v)).do((r) => {
|
|
760
|
+
if (isValue(r))
|
|
761
|
+
job.throw(new Error("Stream ended"));
|
|
762
|
+
else if (isError(r))
|
|
763
|
+
job.throw(markHandled(r));
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
mustBeSourceOrSignal();
|
|
767
|
+
}
|
|
768
|
+
function mustBeSourceOrSignal() {
|
|
769
|
+
throw new TypeError("not a source or signal");
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export { CancelError as A, nativePromise as B, CancelResult as C, makeJob as D, ErrorResult as E, pipe as F, compose as G, into as H, IsStream as I, isJobActive as J, timeout as K, abortSignal as L, task as M, swapCtx as N, nullCtx as O, ruleQueue as P, defaultQ as Q, currentRule as R, makeCtx as S, ruleStops as T, freeCtx as U, ValueResult as V, rejecter as a, resolve as b, backpressure as c, defer as d, detached as e, isUnhandled as f, getJob as g, markHandled as h, isCancel as i, isError as j, connect as k, fulfillPromise as l, must as m, noop as n, callOrWait as o, restarting as p, current as q, resolver as r, start as s, throttle as t, mustBeSourceOrSignal as u, isValue as v, reject as w, isHandled as x, getResult as y, propagateResult as z };
|
|
773
|
+
//# sourceMappingURL=call-or-wait-DHkBd_bM.mjs.map
|