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
package/dist/mod.mjs
CHANGED
|
@@ -1,513 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
request("next", val);
|
|
5
|
-
}
|
|
6
|
-
function reject(request, reason) {
|
|
7
|
-
request("throw", void 0, reason);
|
|
8
|
-
}
|
|
9
|
-
function resolver(request) {
|
|
10
|
-
return request.bind(null, "next");
|
|
11
|
-
}
|
|
12
|
-
function rejecter(request) {
|
|
13
|
-
return request.bind(null, "throw", void 0);
|
|
14
|
-
}
|
|
15
|
-
function noop() {
|
|
16
|
-
}
|
|
17
|
-
function mkResult(op, val, err) {
|
|
18
|
-
return { op, val, err };
|
|
19
|
-
}
|
|
20
|
-
const CancelResult = Object.freeze(mkResult("cancel"));
|
|
21
|
-
function ValueResult(val) {
|
|
22
|
-
return mkResult("next", val);
|
|
23
|
-
}
|
|
24
|
-
function ErrorResult(err) {
|
|
25
|
-
return mkResult("throw", void 0, err);
|
|
26
|
-
}
|
|
27
|
-
function isCancel(res) {
|
|
28
|
-
return res === CancelResult;
|
|
29
|
-
}
|
|
30
|
-
function isValue(res) {
|
|
31
|
-
return res ? res.op === "next" : false;
|
|
32
|
-
}
|
|
33
|
-
function isError(res) {
|
|
34
|
-
return res ? res.op === "throw" : false;
|
|
35
|
-
}
|
|
36
|
-
function isUnhandled(res) {
|
|
37
|
-
return isError(res) && res.val === void 0;
|
|
38
|
-
}
|
|
39
|
-
function isHandled(res) {
|
|
40
|
-
return isError(res) && res.val === null;
|
|
41
|
-
}
|
|
42
|
-
function markHandled(res) {
|
|
43
|
-
res.val = null;
|
|
44
|
-
return res.err;
|
|
45
|
-
}
|
|
46
|
-
function getResult(res) {
|
|
47
|
-
if (isValue(res))
|
|
48
|
-
return res.val;
|
|
49
|
-
res.op;
|
|
50
|
-
fulfillPromise(noop, (e) => {
|
|
51
|
-
throw e;
|
|
52
|
-
}, res);
|
|
53
|
-
}
|
|
54
|
-
function fulfillPromise(resolve2, reject2, res) {
|
|
55
|
-
if (isError(res))
|
|
56
|
-
reject2(markHandled(res));
|
|
57
|
-
else if (isCancel(res))
|
|
58
|
-
reject2(new CancelError("Job canceled"));
|
|
59
|
-
else
|
|
60
|
-
resolve2(res.val);
|
|
61
|
-
}
|
|
62
|
-
function propagateResult(job, res) {
|
|
63
|
-
if (!job.result())
|
|
64
|
-
fulfillPromise(job.return.bind(job), job.throw.bind(job), res);
|
|
65
|
-
}
|
|
66
|
-
class CancelError extends Error {
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var current = makeCtx();
|
|
70
|
-
function swapCtx(future) {
|
|
71
|
-
const now = current;
|
|
72
|
-
current = future;
|
|
73
|
-
return now;
|
|
74
|
-
}
|
|
75
|
-
var freelist = [];
|
|
76
|
-
function makeCtx(job, cell) {
|
|
77
|
-
if (freelist && freelist.length) {
|
|
78
|
-
const s = freelist.pop();
|
|
79
|
-
s.job = job;
|
|
80
|
-
s.cell = cell;
|
|
81
|
-
return s;
|
|
82
|
-
}
|
|
83
|
-
return { job, cell };
|
|
84
|
-
}
|
|
85
|
-
function freeCtx(s) {
|
|
86
|
-
s.job = s.cell = null;
|
|
87
|
-
freelist.push(s);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const catchers = /* @__PURE__ */ new WeakMap(), defaultCatch = (e) => {
|
|
91
|
-
Promise.reject(e);
|
|
92
|
-
};
|
|
93
|
-
const nullCtx = makeCtx();
|
|
94
|
-
const owners = /* @__PURE__ */ new WeakMap();
|
|
95
|
-
|
|
96
|
-
function chain() {
|
|
97
|
-
return link(0, void 0, void 0);
|
|
98
|
-
}
|
|
99
|
-
function recycle(c) {
|
|
100
|
-
while (c.v)
|
|
101
|
-
unlink(c, c.n);
|
|
102
|
-
c.u = void 0;
|
|
103
|
-
unlink(c, c);
|
|
104
|
-
}
|
|
105
|
-
function unshift(c, v) {
|
|
106
|
-
++c.v;
|
|
107
|
-
link(v, c.n, c);
|
|
108
|
-
}
|
|
109
|
-
function push(c, v) {
|
|
110
|
-
++c.v;
|
|
111
|
-
link(v, c, c.p);
|
|
112
|
-
}
|
|
113
|
-
function pushCB(c, v) {
|
|
114
|
-
++c.v;
|
|
115
|
-
return unlinker(c, link(v, c, c.p));
|
|
116
|
-
}
|
|
117
|
-
function isEmpty(c) {
|
|
118
|
-
return !c || c.v === 0;
|
|
119
|
-
}
|
|
120
|
-
function qlen(c) {
|
|
121
|
-
return c ? c.v : 0;
|
|
122
|
-
}
|
|
123
|
-
function pop(c) {
|
|
124
|
-
if (qlen(c))
|
|
125
|
-
return unlink(c, c.p);
|
|
126
|
-
}
|
|
127
|
-
class Node {
|
|
128
|
-
constructor() {
|
|
129
|
-
/** The next node (or the start node if this is a chain head) */
|
|
130
|
-
this.n = this;
|
|
131
|
-
/** The previous node (or the end node if this is a chain head) */
|
|
132
|
-
this.p = this;
|
|
133
|
-
/** The value held by the node (or the chain length if this is a chain head) */
|
|
134
|
-
this.v = 0;
|
|
135
|
-
/** The most recently created undo callback for this node */
|
|
136
|
-
this.u = void 0;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
var free;
|
|
140
|
-
function link(v, n, p) {
|
|
141
|
-
let node = free;
|
|
142
|
-
if (node) {
|
|
143
|
-
free = node.n;
|
|
144
|
-
node.n = n || node;
|
|
145
|
-
node.p = p || node;
|
|
146
|
-
} else {
|
|
147
|
-
node = new Node();
|
|
148
|
-
if (n)
|
|
149
|
-
node.n = n;
|
|
150
|
-
if (p)
|
|
151
|
-
node.p = p;
|
|
152
|
-
}
|
|
153
|
-
node.v = v;
|
|
154
|
-
node.n.p = node;
|
|
155
|
-
node.p.n = node;
|
|
156
|
-
return node;
|
|
157
|
-
}
|
|
158
|
-
function unlink(c, node) {
|
|
159
|
-
--c.v;
|
|
160
|
-
var v = node.v, u = node.u;
|
|
161
|
-
node.n && (node.n.p = node.p);
|
|
162
|
-
node.p && (node.p.n = node.n);
|
|
163
|
-
node.u = node.v = node.p = void 0;
|
|
164
|
-
node.n = free;
|
|
165
|
-
free = node;
|
|
166
|
-
if (u)
|
|
167
|
-
u();
|
|
168
|
-
return v;
|
|
169
|
-
}
|
|
170
|
-
function unlinker(chain2, node) {
|
|
171
|
-
let u = node.u ||= () => {
|
|
172
|
-
if (u) {
|
|
173
|
-
if (u === node.u)
|
|
174
|
-
unlink(chain2, node);
|
|
175
|
-
u = chain2 = node = void 0;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
return u;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function isFunction(f) {
|
|
182
|
-
return typeof f === "function";
|
|
183
|
-
}
|
|
184
|
-
function getJob() {
|
|
185
|
-
const { job } = current;
|
|
186
|
-
if (job)
|
|
187
|
-
return job;
|
|
188
|
-
throw new Error("No job is currently active");
|
|
189
|
-
}
|
|
190
|
-
function recalcJob(job) {
|
|
191
|
-
return (cb) => {
|
|
192
|
-
current.job.must(job.release(cb));
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function runChain(res, cbs) {
|
|
196
|
-
while (qlen(cbs))
|
|
197
|
-
try {
|
|
198
|
-
pop(cbs)(res);
|
|
199
|
-
} catch (e) {
|
|
200
|
-
detached.asyncThrow(e);
|
|
201
|
-
}
|
|
202
|
-
cbs && recycle(cbs);
|
|
203
|
-
return void 0;
|
|
204
|
-
}
|
|
205
|
-
var inProcess = /* @__PURE__ */ new Set();
|
|
206
|
-
class _Job {
|
|
207
|
-
constructor() {
|
|
208
|
-
this.end = () => {
|
|
209
|
-
const res = this._done ||= CancelResult, cbs = this._cbs;
|
|
210
|
-
if (!cbs && !isUnhandled(res))
|
|
211
|
-
return;
|
|
212
|
-
const ct = inProcess.size, old = swapCtx(nullCtx);
|
|
213
|
-
if (!ct)
|
|
214
|
-
inProcess.add(null);
|
|
215
|
-
if (cbs && cbs.u)
|
|
216
|
-
cbs.u = runChain(res, cbs.u);
|
|
217
|
-
inProcess.add(this);
|
|
218
|
-
if (ct) {
|
|
219
|
-
swapCtx(old);
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
inProcess.delete(null);
|
|
223
|
-
for (const item of inProcess) {
|
|
224
|
-
if (item._cbs)
|
|
225
|
-
item._cbs = runChain(item._done, item._cbs);
|
|
226
|
-
inProcess.delete(item);
|
|
227
|
-
if (isUnhandled(item._done))
|
|
228
|
-
item.throw(markHandled(item._done));
|
|
229
|
-
}
|
|
230
|
-
swapCtx(old);
|
|
231
|
-
};
|
|
232
|
-
this._done = void 0;
|
|
233
|
-
// Chain whose .u stores a second chain for `release()` callbacks
|
|
234
|
-
this._cbs = void 0;
|
|
235
|
-
}
|
|
236
|
-
/** @internal */
|
|
237
|
-
static create(parent, stop) {
|
|
238
|
-
const job = new _Job();
|
|
239
|
-
if (parent || stop) {
|
|
240
|
-
job.must((parent ||= getJob()).release(stop || job.end));
|
|
241
|
-
owners.set(job, parent);
|
|
242
|
-
}
|
|
243
|
-
return job;
|
|
244
|
-
}
|
|
245
|
-
do(cleanup) {
|
|
246
|
-
unshift(this._chain(), cleanup);
|
|
247
|
-
return this;
|
|
248
|
-
}
|
|
249
|
-
onError(cb) {
|
|
250
|
-
return this.do((r) => {
|
|
251
|
-
if (isError(r))
|
|
252
|
-
cb(markHandled(r));
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
onValue(cb) {
|
|
256
|
-
return this.do((r) => {
|
|
257
|
-
if (isValue(r))
|
|
258
|
-
cb(r.val);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
onCancel(cb) {
|
|
262
|
-
return this.do((r) => {
|
|
263
|
-
if (isCancel(r))
|
|
264
|
-
cb();
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
result() {
|
|
268
|
-
return this._done || current.cell?.recalcWhen(this, recalcJob) || void 0;
|
|
269
|
-
}
|
|
270
|
-
get [Symbol.toStringTag]() {
|
|
271
|
-
return "Job";
|
|
272
|
-
}
|
|
273
|
-
restart() {
|
|
274
|
-
if (!this._done && inProcess.size) {
|
|
275
|
-
const old = inProcess;
|
|
276
|
-
inProcess = /* @__PURE__ */ new Set();
|
|
277
|
-
this.end();
|
|
278
|
-
inProcess = old;
|
|
279
|
-
} else {
|
|
280
|
-
this._end(CancelResult);
|
|
281
|
-
}
|
|
282
|
-
this._done = void 0;
|
|
283
|
-
promises.delete(this);
|
|
284
|
-
return this;
|
|
285
|
-
}
|
|
286
|
-
_end(res) {
|
|
287
|
-
if (this._done)
|
|
288
|
-
throw new Error("Job already ended");
|
|
289
|
-
if (this !== detached)
|
|
290
|
-
this._done = res;
|
|
291
|
-
this.end();
|
|
292
|
-
return this;
|
|
293
|
-
}
|
|
294
|
-
throw(err) {
|
|
295
|
-
if (this._done) {
|
|
296
|
-
(owners.get(this) || detached).asyncThrow(err);
|
|
297
|
-
return this;
|
|
298
|
-
}
|
|
299
|
-
return this._end(ErrorResult(err));
|
|
300
|
-
}
|
|
301
|
-
return(val) {
|
|
302
|
-
return this._end(ValueResult(val));
|
|
303
|
-
}
|
|
304
|
-
then(onfulfilled, onrejected) {
|
|
305
|
-
return nativePromise(this).then(onfulfilled, onrejected);
|
|
306
|
-
}
|
|
307
|
-
catch(onrejected) {
|
|
308
|
-
return nativePromise(this).catch(onrejected);
|
|
309
|
-
}
|
|
310
|
-
finally(onfinally) {
|
|
311
|
-
return nativePromise(this).finally(onfinally);
|
|
312
|
-
}
|
|
313
|
-
*[Symbol.iterator]() {
|
|
314
|
-
if (this._done) {
|
|
315
|
-
return getResult(this._done);
|
|
316
|
-
} else
|
|
317
|
-
return yield (req) => {
|
|
318
|
-
this.do((res) => fulfillPromise(resolver(req), rejecter(req), res));
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
start(fnOrCtx, fn) {
|
|
322
|
-
if (!fnOrCtx)
|
|
323
|
-
return makeJob(this);
|
|
324
|
-
let init, result;
|
|
325
|
-
if (isFunction(fn)) {
|
|
326
|
-
init = fn.bind(fnOrCtx);
|
|
327
|
-
} else if (isFunction(fnOrCtx)) {
|
|
328
|
-
init = fnOrCtx;
|
|
329
|
-
} else if (fnOrCtx instanceof _Job) {
|
|
330
|
-
return fnOrCtx;
|
|
331
|
-
} else {
|
|
332
|
-
result = fnOrCtx;
|
|
333
|
-
}
|
|
334
|
-
const job = makeJob(this);
|
|
335
|
-
try {
|
|
336
|
-
if (init)
|
|
337
|
-
result = job.run(init, job);
|
|
338
|
-
if (result != null) {
|
|
339
|
-
if (result instanceof _Job) {
|
|
340
|
-
if (result !== job)
|
|
341
|
-
result.do((res) => propagateResult(job, res));
|
|
342
|
-
} else if (isFunction(result.then)) {
|
|
343
|
-
result.then(
|
|
344
|
-
(v) => {
|
|
345
|
-
job.result() || job.return(v);
|
|
346
|
-
},
|
|
347
|
-
(e) => {
|
|
348
|
-
job.result() || job.throw(e);
|
|
349
|
-
}
|
|
350
|
-
);
|
|
351
|
-
return job;
|
|
352
|
-
} else if (isFunction(result[Symbol.iterator]) && typeof result !== "string") {
|
|
353
|
-
job.run(runGen, result, job);
|
|
354
|
-
} else if (isFunction(result)) {
|
|
355
|
-
job.must(result);
|
|
356
|
-
} else {
|
|
357
|
-
throw new TypeError("Invalid value/return for start()");
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return job;
|
|
361
|
-
} catch (e) {
|
|
362
|
-
job.end();
|
|
363
|
-
throw e;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
connect(src, sink, inlet) {
|
|
367
|
-
return this.start((job) => void src(sink, job, inlet));
|
|
368
|
-
}
|
|
369
|
-
run(fn, ...args) {
|
|
370
|
-
const old = swapCtx(makeCtx(this));
|
|
371
|
-
try {
|
|
372
|
-
return fn.apply(null, args);
|
|
373
|
-
} finally {
|
|
374
|
-
freeCtx(swapCtx(old));
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
bind(fn) {
|
|
378
|
-
const job = this;
|
|
379
|
-
return function() {
|
|
380
|
-
const old = swapCtx(makeCtx(job));
|
|
381
|
-
try {
|
|
382
|
-
return fn.apply(this, arguments);
|
|
383
|
-
} finally {
|
|
384
|
-
freeCtx(swapCtx(old));
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
must(cleanup) {
|
|
389
|
-
if (isFunction(cleanup))
|
|
390
|
-
push(this._chain(), cleanup);
|
|
391
|
-
return this;
|
|
392
|
-
}
|
|
393
|
-
release(cleanup) {
|
|
394
|
-
if (this === detached)
|
|
395
|
-
return noop;
|
|
396
|
-
let cbs = this._chain();
|
|
397
|
-
if (!this._done || cbs.u)
|
|
398
|
-
cbs = cbs.u ||= chain();
|
|
399
|
-
return pushCB(cbs, cleanup);
|
|
400
|
-
}
|
|
401
|
-
asyncThrow(err) {
|
|
402
|
-
try {
|
|
403
|
-
(catchers.get(this) || this.throw).call(this, err);
|
|
404
|
-
} catch (e) {
|
|
405
|
-
if (this === detached)
|
|
406
|
-
catchers.set(this, defaultCatch);
|
|
407
|
-
else
|
|
408
|
-
catchers.delete(this);
|
|
409
|
-
const catcher = catchers.get(this) || this.throw;
|
|
410
|
-
catcher.call(this, err);
|
|
411
|
-
catcher.call(this, e);
|
|
412
|
-
}
|
|
413
|
-
return this;
|
|
414
|
-
}
|
|
415
|
-
asyncCatch(handler) {
|
|
416
|
-
if (isFunction(handler))
|
|
417
|
-
catchers.set(this, handler);
|
|
418
|
-
else if (handler === null)
|
|
419
|
-
catchers.delete(this);
|
|
420
|
-
return this;
|
|
421
|
-
}
|
|
422
|
-
_chain() {
|
|
423
|
-
if (this === detached)
|
|
424
|
-
this.end();
|
|
425
|
-
if (this._done && isEmpty(this._cbs))
|
|
426
|
-
defer(this.end);
|
|
427
|
-
return this._cbs ||= chain();
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const promises = /* @__PURE__ */ new WeakMap();
|
|
431
|
-
function nativePromise(job = getJob()) {
|
|
432
|
-
if (!promises.has(job)) {
|
|
433
|
-
promises.set(job, new Promise((res, rej) => {
|
|
434
|
-
const toPromise = fulfillPromise.bind(null, res, rej);
|
|
435
|
-
if (job.result())
|
|
436
|
-
toPromise(job.result());
|
|
437
|
-
else
|
|
438
|
-
job.do(toPromise);
|
|
439
|
-
}));
|
|
440
|
-
}
|
|
441
|
-
return promises.get(job);
|
|
442
|
-
}
|
|
443
|
-
const makeJob = _Job.create;
|
|
444
|
-
const detached = makeJob();
|
|
445
|
-
detached.end = () => {
|
|
446
|
-
throw new Error("Can't do that with the detached job");
|
|
447
|
-
};
|
|
448
|
-
detached.asyncCatch(defaultCatch);
|
|
449
|
-
function runGen(g, job) {
|
|
450
|
-
let it = g[Symbol.iterator](), running = true, ctx = makeCtx(job), ct = 0;
|
|
451
|
-
let done = ctx.job.release(() => {
|
|
452
|
-
job = void 0;
|
|
453
|
-
++ct;
|
|
454
|
-
step("return", void 0);
|
|
455
|
-
});
|
|
456
|
-
defer(() => {
|
|
457
|
-
running = false;
|
|
458
|
-
step("next", void 0);
|
|
459
|
-
});
|
|
460
|
-
function step(method, arg) {
|
|
461
|
-
if (!it)
|
|
462
|
-
return;
|
|
463
|
-
if (running) {
|
|
464
|
-
return defer(step.bind(null, method, arg));
|
|
465
|
-
}
|
|
466
|
-
const old = swapCtx(ctx);
|
|
467
|
-
try {
|
|
468
|
-
running = true;
|
|
469
|
-
try {
|
|
470
|
-
for (; ; ) {
|
|
471
|
-
++ct;
|
|
472
|
-
const { done: done2, value } = it[method](arg);
|
|
473
|
-
if (done2) {
|
|
474
|
-
job && job.return(value);
|
|
475
|
-
job = void 0;
|
|
476
|
-
break;
|
|
477
|
-
} else if (!isFunction(value)) {
|
|
478
|
-
method = "throw";
|
|
479
|
-
arg = new TypeError("Jobs must yield functions (or yield* Yielding<T>s)");
|
|
480
|
-
continue;
|
|
481
|
-
} else {
|
|
482
|
-
let called = false, returned = false, count = ct;
|
|
483
|
-
value((op, val, err) => {
|
|
484
|
-
if (called)
|
|
485
|
-
return;
|
|
486
|
-
else
|
|
487
|
-
called = true;
|
|
488
|
-
method = op;
|
|
489
|
-
arg = op === "next" ? val : err;
|
|
490
|
-
if (returned && count === ct)
|
|
491
|
-
step(op, arg);
|
|
492
|
-
});
|
|
493
|
-
returned = true;
|
|
494
|
-
if (!called)
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
} catch (e) {
|
|
499
|
-
it = job = void 0;
|
|
500
|
-
ctx.job.throw(e);
|
|
501
|
-
}
|
|
502
|
-
it = void 0;
|
|
503
|
-
done?.();
|
|
504
|
-
done = void 0;
|
|
505
|
-
} finally {
|
|
506
|
-
swapCtx(old);
|
|
507
|
-
running = false;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
1
|
+
import { r as resolver, a as rejecter, b as resolve, I as IsStream, c as backpressure, m as must, s as start, g as getJob, n as noop, d as defer, t as throttle, e as detached, i as isCancel, f as isUnhandled, h as markHandled, j as isError, k as connect, l as fulfillPromise, o as callOrWait, p as restarting, q as current, u as mustBeSourceOrSignal, v as isValue } from './call-or-wait-DHkBd_bM.mjs';
|
|
2
|
+
export { A as CancelError, C as CancelResult, E as ErrorResult, V as ValueResult, L as abortSignal, G as compose, y as getResult, H as into, x as isHandled, J as isJobActive, D as makeJob, B as nativePromise, F as pipe, z as propagateResult, w as reject, M as task, K as timeout } from './call-or-wait-DHkBd_bM.mjs';
|
|
3
|
+
import { isFunction } from './utils.mjs';
|
|
511
4
|
|
|
512
5
|
function* to(p) {
|
|
513
6
|
return yield (res) => Promise.resolve(p).then(resolver(res), rejecter(res));
|
|
@@ -527,809 +20,6 @@ function* sleep(ms) {
|
|
|
527
20
|
}
|
|
528
21
|
}
|
|
529
22
|
|
|
530
|
-
class RunQueue {
|
|
531
|
-
constructor(sched, reap) {
|
|
532
|
-
this.sched = sched;
|
|
533
|
-
this.reap = reap;
|
|
534
|
-
this._flags = 0 /* Unset */;
|
|
535
|
-
this.q = /* @__PURE__ */ new Set();
|
|
536
|
-
this._run = () => {
|
|
537
|
-
this._flags &= ~2 /* Scheduled */;
|
|
538
|
-
this.flush();
|
|
539
|
-
};
|
|
540
|
-
/** Run all pending items */
|
|
541
|
-
this.flush = () => {
|
|
542
|
-
if (this._flags & 1 /* Running */)
|
|
543
|
-
return;
|
|
544
|
-
const { q: queue } = this;
|
|
545
|
-
if (!queue.size)
|
|
546
|
-
return;
|
|
547
|
-
this._flags |= 1 /* Running */;
|
|
548
|
-
try {
|
|
549
|
-
this.reap(queue);
|
|
550
|
-
} finally {
|
|
551
|
-
this._flags &= ~1 /* Running */;
|
|
552
|
-
!queue.size || this._flags & 2 /* Scheduled */ || this._sched();
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
/** Is this queue currently running? */
|
|
557
|
-
isRunning() {
|
|
558
|
-
return !!(this._flags & 1 /* Running */);
|
|
559
|
-
}
|
|
560
|
-
/** Is this queue currently empty? */
|
|
561
|
-
isEmpty() {
|
|
562
|
-
return !this.q.size;
|
|
563
|
-
}
|
|
564
|
-
add(subject) {
|
|
565
|
-
this.q.size || this._flags & (1 /* Running */ | 2 /* Scheduled */) || this._sched();
|
|
566
|
-
this.q.add(subject);
|
|
567
|
-
}
|
|
568
|
-
delete(subject) {
|
|
569
|
-
this.q.delete(subject);
|
|
570
|
-
}
|
|
571
|
-
_sched() {
|
|
572
|
-
this._flags |= 2 /* Scheduled */;
|
|
573
|
-
this.sched(this._run);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
var currentRule;
|
|
577
|
-
var currentQueue;
|
|
578
|
-
const ruleQueues = /* @__PURE__ */ new WeakMap();
|
|
579
|
-
class RuleQueue extends RunQueue {
|
|
580
|
-
constructor(sched) {
|
|
581
|
-
super(sched, function(q) {
|
|
582
|
-
if (currentQueue)
|
|
583
|
-
return;
|
|
584
|
-
currentQueue = this;
|
|
585
|
-
try {
|
|
586
|
-
for (currentRule of q) {
|
|
587
|
-
currentRule.catchUp();
|
|
588
|
-
q.delete(currentRule);
|
|
589
|
-
}
|
|
590
|
-
} finally {
|
|
591
|
-
currentQueue = currentRule = void 0;
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
function ruleQueue(scheduleFn = defer) {
|
|
597
|
-
ruleQueues.has(scheduleFn) || ruleQueues.set(scheduleFn, new RuleQueue(scheduleFn));
|
|
598
|
-
return ruleQueues.get(scheduleFn);
|
|
599
|
-
}
|
|
600
|
-
const defaultQ = /* @__PURE__ */ ruleQueue(defer);
|
|
601
|
-
const pulls = new RunQueue(defer, (pulls2) => {
|
|
602
|
-
for (const conn of pulls2) {
|
|
603
|
-
pulls2.delete(conn);
|
|
604
|
-
conn.doPull();
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
pulls.flush;
|
|
608
|
-
|
|
609
|
-
function backpressure(inlet = defaultInlet) {
|
|
610
|
-
const job = getJob();
|
|
611
|
-
return (cb) => {
|
|
612
|
-
if (!job.result() && inlet.isOpen()) {
|
|
613
|
-
if (cb)
|
|
614
|
-
inlet.onReady(cb, job);
|
|
615
|
-
return inlet.isReady();
|
|
616
|
-
}
|
|
617
|
-
return false;
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
const IsStream = "uneventful/is-stream";
|
|
621
|
-
function connect(src, sink, inlet) {
|
|
622
|
-
return getJob().connect(src, sink, inlet);
|
|
623
|
-
}
|
|
624
|
-
function throttle(job = current.job) {
|
|
625
|
-
return new _Throttle(job);
|
|
626
|
-
}
|
|
627
|
-
class _Throttle {
|
|
628
|
-
/** @internal */
|
|
629
|
-
constructor(_job) {
|
|
630
|
-
this._job = _job;
|
|
631
|
-
/** @internal */
|
|
632
|
-
this._callbacks = void 0;
|
|
633
|
-
this._isReady = true;
|
|
634
|
-
this._isPulling = false;
|
|
635
|
-
}
|
|
636
|
-
isOpen() {
|
|
637
|
-
return !this._job?.result();
|
|
638
|
-
}
|
|
639
|
-
/** Is the conduit currently ready to receive data? */
|
|
640
|
-
isReady() {
|
|
641
|
-
return this.isOpen() && this._isReady;
|
|
642
|
-
}
|
|
643
|
-
onReady(cb, job) {
|
|
644
|
-
if (!this.isOpen())
|
|
645
|
-
return this;
|
|
646
|
-
const _callbacks = this._callbacks ||= /* @__PURE__ */ new Map();
|
|
647
|
-
const unlink = job.release(() => _callbacks.delete(cb));
|
|
648
|
-
if (this.isReady() && this && !_callbacks.size) {
|
|
649
|
-
pulls.add(this);
|
|
650
|
-
}
|
|
651
|
-
_callbacks.set(cb, unlink);
|
|
652
|
-
return this;
|
|
653
|
-
}
|
|
654
|
-
pause() {
|
|
655
|
-
this._isReady = false;
|
|
656
|
-
return this;
|
|
657
|
-
}
|
|
658
|
-
doPull() {
|
|
659
|
-
if (this._isPulling)
|
|
660
|
-
return;
|
|
661
|
-
const { _callbacks } = this;
|
|
662
|
-
if (!_callbacks?.size)
|
|
663
|
-
return;
|
|
664
|
-
this._isPulling = true;
|
|
665
|
-
try {
|
|
666
|
-
for (let [cb, unlink] of _callbacks) {
|
|
667
|
-
if (!this.isReady())
|
|
668
|
-
break;
|
|
669
|
-
unlink();
|
|
670
|
-
_callbacks.delete(cb);
|
|
671
|
-
cb();
|
|
672
|
-
}
|
|
673
|
-
} finally {
|
|
674
|
-
this._isPulling = false;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
resume() {
|
|
678
|
-
if (this.isOpen()) {
|
|
679
|
-
this._isReady = true;
|
|
680
|
-
this.doPull();
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
const defaultInlet = throttle();
|
|
685
|
-
function pipe() {
|
|
686
|
-
var v = arguments[0];
|
|
687
|
-
for (var i = 1; i < arguments.length; i++)
|
|
688
|
-
v = arguments[i](v);
|
|
689
|
-
return v;
|
|
690
|
-
}
|
|
691
|
-
function compose(...fns) {
|
|
692
|
-
return (val) => pipe(val, ...fns);
|
|
693
|
-
}
|
|
694
|
-
function into(...args) {
|
|
695
|
-
return (src) => src(...args);
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
function setMap(map, key, val) {
|
|
699
|
-
map.set(key, val);
|
|
700
|
-
return val;
|
|
701
|
-
}
|
|
702
|
-
function CallableObject(fn) {
|
|
703
|
-
return Object.setPrototypeOf(fn, new.target.prototype);
|
|
704
|
-
}
|
|
705
|
-
CallableObject.prototype = Function.prototype;
|
|
706
|
-
|
|
707
|
-
class WriteConflict extends Error {
|
|
708
|
-
}
|
|
709
|
-
class CircularDependency extends Error {
|
|
710
|
-
}
|
|
711
|
-
var timestamp = 1;
|
|
712
|
-
const fntrackers = /* @__PURE__ */ new WeakMap();
|
|
713
|
-
const obtrackers = /* @__PURE__ */ new WeakMap();
|
|
714
|
-
const dirtyStack = [];
|
|
715
|
-
function markDependentsDirty(cell) {
|
|
716
|
-
const latestSource = cell.latestSource = timestamp;
|
|
717
|
-
for (; cell; cell = dirtyStack.pop()) {
|
|
718
|
-
for (let sub = cell.subscribers; sub; sub = sub.nT) {
|
|
719
|
-
const tgt = sub.tgt;
|
|
720
|
-
if (tgt.latestSource >= latestSource)
|
|
721
|
-
continue;
|
|
722
|
-
tgt.latestSource = latestSource;
|
|
723
|
-
if (tgt.flags & 1 /* Rule */)
|
|
724
|
-
tgt.value.q.add(tgt);
|
|
725
|
-
if (tgt.subscribers)
|
|
726
|
-
dirtyStack.push(tgt);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
function returnValue() {
|
|
731
|
-
return this.value;
|
|
732
|
-
}
|
|
733
|
-
function throwValue() {
|
|
734
|
-
throw this.value;
|
|
735
|
-
}
|
|
736
|
-
const notCaughtUp = [];
|
|
737
|
-
var freesubs;
|
|
738
|
-
function mksub(source, target) {
|
|
739
|
-
let sub = freesubs;
|
|
740
|
-
if (sub) {
|
|
741
|
-
freesubs = sub.old;
|
|
742
|
-
sub.src = source;
|
|
743
|
-
sub.nS = void 0;
|
|
744
|
-
sub.pS = target.sources;
|
|
745
|
-
sub.tgt = target;
|
|
746
|
-
sub.nT = sub.pT = void 0;
|
|
747
|
-
sub.ts = source.lastChanged;
|
|
748
|
-
sub.old = source.adding;
|
|
749
|
-
} else
|
|
750
|
-
sub = {
|
|
751
|
-
src: source,
|
|
752
|
-
nS: void 0,
|
|
753
|
-
pS: target.sources,
|
|
754
|
-
tgt: target,
|
|
755
|
-
nT: void 0,
|
|
756
|
-
pT: void 0,
|
|
757
|
-
ts: source.lastChanged,
|
|
758
|
-
old: source.adding
|
|
759
|
-
};
|
|
760
|
-
if (target.sources)
|
|
761
|
-
target.sources.nS = sub;
|
|
762
|
-
target.sources = sub;
|
|
763
|
-
source.adding = sub;
|
|
764
|
-
if (target.subscribers || target.flags & 1 /* Rule */)
|
|
765
|
-
source.subscribe(sub);
|
|
766
|
-
}
|
|
767
|
-
function delsub(sub) {
|
|
768
|
-
sub.src.unsubscribe(sub);
|
|
769
|
-
if (sub.nS)
|
|
770
|
-
sub.nS.pS = sub.pS;
|
|
771
|
-
if (sub.pS)
|
|
772
|
-
sub.pS.nS = sub.nS;
|
|
773
|
-
sub.src = sub.tgt = sub.nS = sub.pS = sub.nT = sub.pT = void 0;
|
|
774
|
-
sub.old = freesubs;
|
|
775
|
-
freesubs = sub;
|
|
776
|
-
}
|
|
777
|
-
const sentinel = {};
|
|
778
|
-
class Cell {
|
|
779
|
-
constructor() {
|
|
780
|
-
this.value = void 0;
|
|
781
|
-
// the value, or, for a rule, the `{q, rm}` struct
|
|
782
|
-
this.validThrough = 0;
|
|
783
|
-
// timestamp of most recent validation or recalculation
|
|
784
|
-
this.lastChanged = 0;
|
|
785
|
-
// timestamp of last value change
|
|
786
|
-
this.latestSource = timestamp;
|
|
787
|
-
// max lastChanged of this cell or any ancestor source
|
|
788
|
-
this.flags = 0;
|
|
789
|
-
this.ctx = void 0;
|
|
790
|
-
/** The subscription being added during the current calculation - used for uniqueness */
|
|
791
|
-
this.adding = void 0;
|
|
792
|
-
/** Linked list of sources */
|
|
793
|
-
this.sources = void 0;
|
|
794
|
-
/** Linked list of targets */
|
|
795
|
-
this.subscribers = void 0;
|
|
796
|
-
/**
|
|
797
|
-
* The computation to be performed (if {@link Is.Calc} or {@link Is.Rule})
|
|
798
|
-
* or the setup/teardown for {@link Is.Stream}.
|
|
799
|
-
*/
|
|
800
|
-
this.compute = returnValue;
|
|
801
|
-
}
|
|
802
|
-
stream(sink, _conn, inlet) {
|
|
803
|
-
let lastValue = sentinel;
|
|
804
|
-
Cell.mkRule(() => {
|
|
805
|
-
const val = this.getValue();
|
|
806
|
-
if (val !== lastValue) {
|
|
807
|
-
const old = swapCtx(nullCtx);
|
|
808
|
-
try {
|
|
809
|
-
sink(lastValue = val);
|
|
810
|
-
} finally {
|
|
811
|
-
swapCtx(old);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}, inlet ? ruleQueue(backpressure(inlet)) : defaultQ);
|
|
815
|
-
return IsStream;
|
|
816
|
-
}
|
|
817
|
-
getValue() {
|
|
818
|
-
if (arguments.length)
|
|
819
|
-
return this.stream.apply(this, arguments);
|
|
820
|
-
this.catchUp();
|
|
821
|
-
const dep = current.cell;
|
|
822
|
-
if (dep && this.flags & 133 /* Variable */) {
|
|
823
|
-
if (this.flags & 32 /* Running */)
|
|
824
|
-
throw new CircularDependency("Cached function dependency cycle");
|
|
825
|
-
let s = this.adding;
|
|
826
|
-
if (!s || s.tgt !== dep) {
|
|
827
|
-
mksub(this, dep);
|
|
828
|
-
} else {
|
|
829
|
-
if (s.ts === -1) {
|
|
830
|
-
s.ts = this.lastChanged;
|
|
831
|
-
if (s.nS) {
|
|
832
|
-
s.nS.pS = s.pS;
|
|
833
|
-
if (s.pS)
|
|
834
|
-
s.pS.nS = s.nS;
|
|
835
|
-
s.nS = void 0;
|
|
836
|
-
s.pS = dep.sources;
|
|
837
|
-
dep.sources.nS = s;
|
|
838
|
-
dep.sources = s;
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
if (this.flags & 16 /* Error */)
|
|
844
|
-
throw this.value;
|
|
845
|
-
return this.value;
|
|
846
|
-
}
|
|
847
|
-
shouldWrite(changed) {
|
|
848
|
-
const cell = current.cell || currentRule;
|
|
849
|
-
if (cell) {
|
|
850
|
-
if (cell.flags & 4 /* Calc */)
|
|
851
|
-
throw new WriteConflict("Side-effects not allowed in cached functions");
|
|
852
|
-
if (this.adding && this.adding.tgt === cell)
|
|
853
|
-
throw new CircularDependency("Can't update direct dependency");
|
|
854
|
-
if (this.validThrough === timestamp || this.hasBeenRead())
|
|
855
|
-
throw new WriteConflict("Value already used");
|
|
856
|
-
} else if (changed) {
|
|
857
|
-
if (this.validThrough === timestamp || notCaughtUp.length) {
|
|
858
|
-
++timestamp;
|
|
859
|
-
notCaughtUp.length = 0;
|
|
860
|
-
}
|
|
861
|
-
} else {
|
|
862
|
-
return false;
|
|
863
|
-
}
|
|
864
|
-
this.lastChanged === timestamp || markDependentsDirty(this);
|
|
865
|
-
if (this.sources)
|
|
866
|
-
this.sources.ts = 0;
|
|
867
|
-
return true;
|
|
868
|
-
}
|
|
869
|
-
setValue(val, isErr) {
|
|
870
|
-
if (this.shouldWrite(val !== this.value || isErr !== !!(this.flags & 16 /* Error */))) {
|
|
871
|
-
this.value = val;
|
|
872
|
-
this.lastChanged = timestamp;
|
|
873
|
-
this.flags = isErr ? this.flags | 16 /* Error */ : this.flags & ~16 /* Error */;
|
|
874
|
-
}
|
|
875
|
-
this.compute = isErr ? throwValue : returnValue;
|
|
876
|
-
}
|
|
877
|
-
setCalc(compute) {
|
|
878
|
-
if (this.shouldWrite(compute !== this.compute)) {
|
|
879
|
-
this.flags |= 4 /* Calc */;
|
|
880
|
-
this.compute = compute;
|
|
881
|
-
this.ctx ||= makeCtx(null, this);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
hasBeenRead() {
|
|
885
|
-
if (notCaughtUp.length) {
|
|
886
|
-
for (const cell of notCaughtUp)
|
|
887
|
-
cell.catchUp();
|
|
888
|
-
notCaughtUp.length = 0;
|
|
889
|
-
}
|
|
890
|
-
return this.validThrough === timestamp;
|
|
891
|
-
}
|
|
892
|
-
catchUp() {
|
|
893
|
-
const { validThrough } = this;
|
|
894
|
-
if (validThrough === timestamp)
|
|
895
|
-
return;
|
|
896
|
-
this.validThrough = timestamp;
|
|
897
|
-
if (!(this.flags & 5 /* Computed */))
|
|
898
|
-
return;
|
|
899
|
-
if (this.sources) {
|
|
900
|
-
for (let sub = this.sources; sub; sub = sub.nS) {
|
|
901
|
-
const s = sub.src;
|
|
902
|
-
if (sub.ts !== s.lastChanged)
|
|
903
|
-
return this.doRecalc();
|
|
904
|
-
if (s.subscribers && s.latestSource <= validThrough)
|
|
905
|
-
continue;
|
|
906
|
-
s.catchUp();
|
|
907
|
-
if (s.lastChanged > validThrough) {
|
|
908
|
-
return this.doRecalc();
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
for (let sub = this.sources; sub; sub = sub.nS) {
|
|
912
|
-
if (sub.src.validThrough !== timestamp)
|
|
913
|
-
notCaughtUp.push(sub.src);
|
|
914
|
-
}
|
|
915
|
-
} else
|
|
916
|
-
return this.doRecalc();
|
|
917
|
-
}
|
|
918
|
-
doRecalc() {
|
|
919
|
-
const oldCtx = swapCtx(this.ctx);
|
|
920
|
-
for (let sub = this.sources; sub; sub = sub.nS) {
|
|
921
|
-
sub.ts = -1;
|
|
922
|
-
sub.old = sub.src.adding;
|
|
923
|
-
sub.src.adding = sub;
|
|
924
|
-
this.sources = sub;
|
|
925
|
-
}
|
|
926
|
-
this.flags |= 32 /* Running */;
|
|
927
|
-
try {
|
|
928
|
-
if (this.flags & 4 /* Calc */) {
|
|
929
|
-
try {
|
|
930
|
-
const future = this.compute();
|
|
931
|
-
if (future !== this.value || !this.lastChanged || this.flags & 16 /* Error */) {
|
|
932
|
-
this.value = future;
|
|
933
|
-
this.lastChanged = timestamp;
|
|
934
|
-
}
|
|
935
|
-
this.flags &= ~16 /* Error */;
|
|
936
|
-
} catch (e) {
|
|
937
|
-
this.flags |= 16 /* Error */;
|
|
938
|
-
this.value = e;
|
|
939
|
-
this.lastChanged = timestamp;
|
|
940
|
-
}
|
|
941
|
-
} else {
|
|
942
|
-
const { job } = this.ctx;
|
|
943
|
-
job.restart();
|
|
944
|
-
try {
|
|
945
|
-
job.must(this.compute());
|
|
946
|
-
this.lastChanged = timestamp;
|
|
947
|
-
} catch (e) {
|
|
948
|
-
this.disposeRule();
|
|
949
|
-
throw e;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
} finally {
|
|
953
|
-
this.flags &= ~32 /* Running */;
|
|
954
|
-
swapCtx(oldCtx);
|
|
955
|
-
let head;
|
|
956
|
-
for (let sub = this.sources; sub; ) {
|
|
957
|
-
const pS = sub.pS;
|
|
958
|
-
sub.src.adding = sub.old;
|
|
959
|
-
sub.old = void 0;
|
|
960
|
-
if (sub.ts === -1)
|
|
961
|
-
delsub(sub);
|
|
962
|
-
else
|
|
963
|
-
head = sub;
|
|
964
|
-
sub = pS;
|
|
965
|
-
}
|
|
966
|
-
this.sources = head;
|
|
967
|
-
if (!head) {
|
|
968
|
-
this.flags &= ~4 /* Calc */;
|
|
969
|
-
}
|
|
970
|
-
if (this.flags & 8 /* Dead */)
|
|
971
|
-
this.disposeRule();
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
disposeRule() {
|
|
975
|
-
this.ctx.job.end();
|
|
976
|
-
this.flags |= 8 /* Dead */;
|
|
977
|
-
this.value.q.delete(this);
|
|
978
|
-
this.value.rm();
|
|
979
|
-
if (current !== this.ctx) {
|
|
980
|
-
for (let s = this.sources; s; ) {
|
|
981
|
-
let nS = s.nS;
|
|
982
|
-
delsub(s);
|
|
983
|
-
s = nS;
|
|
984
|
-
}
|
|
985
|
-
this.sources = void 0;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
subscribe(sub) {
|
|
989
|
-
if (!this.subscribers) {
|
|
990
|
-
if (this.flags & 4 /* Calc */) {
|
|
991
|
-
for (let s = this.sources; s; s = s.nS)
|
|
992
|
-
s.src.subscribe(s);
|
|
993
|
-
}
|
|
994
|
-
if (this.flags & 64 /* Stream */)
|
|
995
|
-
this.compute(true);
|
|
996
|
-
}
|
|
997
|
-
if (this.subscribers !== sub && !sub.pT) {
|
|
998
|
-
sub.nT = this.subscribers;
|
|
999
|
-
if (this.subscribers)
|
|
1000
|
-
this.subscribers.pT = sub;
|
|
1001
|
-
this.subscribers = sub;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
unsubscribe(sub) {
|
|
1005
|
-
if (sub.nT)
|
|
1006
|
-
sub.nT.pT = sub.pT;
|
|
1007
|
-
if (sub.pT)
|
|
1008
|
-
sub.pT.nT = sub.nT;
|
|
1009
|
-
if (this.subscribers === sub)
|
|
1010
|
-
this.subscribers = sub.nT;
|
|
1011
|
-
if (!this.subscribers) {
|
|
1012
|
-
if (this.flags & 4 /* Calc */) {
|
|
1013
|
-
for (let s = this.sources; s; s = s.nS)
|
|
1014
|
-
s.src.unsubscribe(s);
|
|
1015
|
-
}
|
|
1016
|
-
if (this.flags & 64 /* Stream */)
|
|
1017
|
-
this.compute(false);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
static mkValue(val) {
|
|
1021
|
-
const cell = new Cell();
|
|
1022
|
-
cell.flags = 128 /* Mutable */;
|
|
1023
|
-
cell.value = val;
|
|
1024
|
-
cell.lastChanged = timestamp;
|
|
1025
|
-
return cell;
|
|
1026
|
-
}
|
|
1027
|
-
static mkStream(src, val) {
|
|
1028
|
-
const cell = this.mkValue(val);
|
|
1029
|
-
cell.flags |= 64 /* Stream */;
|
|
1030
|
-
cell.ctx = makeCtx();
|
|
1031
|
-
const write = (v) => {
|
|
1032
|
-
cell.setValue(v, false);
|
|
1033
|
-
cell.compute = compute;
|
|
1034
|
-
};
|
|
1035
|
-
let job;
|
|
1036
|
-
const compute = cell.compute = (sub) => {
|
|
1037
|
-
if (!sub) {
|
|
1038
|
-
cell.value = val;
|
|
1039
|
-
cell.flags &= ~16 /* Error */;
|
|
1040
|
-
job?.end();
|
|
1041
|
-
return;
|
|
1042
|
-
}
|
|
1043
|
-
if (job)
|
|
1044
|
-
return;
|
|
1045
|
-
job = cell.ctx.job = makeJob().do((r) => {
|
|
1046
|
-
if (isError(r)) {
|
|
1047
|
-
cell.setValue(markHandled(r), true);
|
|
1048
|
-
} else if (isValue(r)) {
|
|
1049
|
-
cell.setValue(val, false);
|
|
1050
|
-
}
|
|
1051
|
-
cell.compute = compute;
|
|
1052
|
-
cell.ctx.job = job = void 0;
|
|
1053
|
-
});
|
|
1054
|
-
const old = swapCtx(cell.ctx);
|
|
1055
|
-
try {
|
|
1056
|
-
src(write, job);
|
|
1057
|
-
} catch (e) {
|
|
1058
|
-
job.end();
|
|
1059
|
-
throw e;
|
|
1060
|
-
} finally {
|
|
1061
|
-
swapCtx(old);
|
|
1062
|
-
}
|
|
1063
|
-
};
|
|
1064
|
-
return cell;
|
|
1065
|
-
}
|
|
1066
|
-
recalcWhen(fnOrKey, fn) {
|
|
1067
|
-
let trackers = fn ? obtrackers.get(fn) || setMap(obtrackers, fn, /* @__PURE__ */ new WeakMap()) : fntrackers;
|
|
1068
|
-
let signal = trackers.get(fnOrKey);
|
|
1069
|
-
if (!signal) {
|
|
1070
|
-
const src = fn ? fn(fnOrKey) : fnOrKey;
|
|
1071
|
-
let ct = 0;
|
|
1072
|
-
const c = Cell.mkStream((s) => (src(() => s(++ct)), IsStream), ct);
|
|
1073
|
-
trackers.set(fnOrKey, signal = c.getValue.bind(c));
|
|
1074
|
-
}
|
|
1075
|
-
signal();
|
|
1076
|
-
}
|
|
1077
|
-
static mkCached(compute) {
|
|
1078
|
-
const cell = new Cell();
|
|
1079
|
-
cell.compute = compute;
|
|
1080
|
-
cell.ctx = makeCtx(null, cell);
|
|
1081
|
-
cell.flags = 4 /* Calc */;
|
|
1082
|
-
return cell;
|
|
1083
|
-
}
|
|
1084
|
-
static mkRule(fn, q) {
|
|
1085
|
-
var cell = new Cell(), job = makeJob();
|
|
1086
|
-
const stop = cell.disposeRule.bind(cell);
|
|
1087
|
-
cell.value = { q, rm: getJob().release(stop) };
|
|
1088
|
-
cell.compute = fn.bind(null, stop);
|
|
1089
|
-
cell.ctx = makeCtx(job, cell);
|
|
1090
|
-
cell.flags = 1 /* Rule */;
|
|
1091
|
-
q.add(cell);
|
|
1092
|
-
return stop;
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
class RF extends CallableObject {
|
|
1097
|
-
constructor(q) {
|
|
1098
|
-
super((fn) => Cell.mkRule(fn, q));
|
|
1099
|
-
}
|
|
1100
|
-
stop() {
|
|
1101
|
-
if (currentRule)
|
|
1102
|
-
return currentRule.disposeRule();
|
|
1103
|
-
throw new Error("No rule active");
|
|
1104
|
-
}
|
|
1105
|
-
if(condition, action) {
|
|
1106
|
-
const cond = Cell.mkCached(() => !!condition());
|
|
1107
|
-
return this(() => cond.getValue() ? action() : void 0);
|
|
1108
|
-
}
|
|
1109
|
-
get method() {
|
|
1110
|
-
const self = this;
|
|
1111
|
-
return (fn, _ctxOrName, desc) => {
|
|
1112
|
-
if (desc)
|
|
1113
|
-
return void (desc.value = this.method(desc.value));
|
|
1114
|
-
return function(...args) {
|
|
1115
|
-
return self(() => fn.apply(this, args));
|
|
1116
|
-
};
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
factory(scheduleFn) {
|
|
1120
|
-
return factories.get(scheduleFn) || setMap(factories, scheduleFn, new RF(ruleQueue(scheduleFn)));
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
const factories = /* @__PURE__ */ new WeakMap();
|
|
1124
|
-
const rule = RF.prototype.factory(defer);
|
|
1125
|
-
function runRules(scheduleFn) {
|
|
1126
|
-
(scheduleFn ? ruleQueue(scheduleFn) : defaultQ).flush();
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
class SignalImpl extends CallableObject {
|
|
1130
|
-
constructor(_c) {
|
|
1131
|
-
super(_c.getValue.bind(_c));
|
|
1132
|
-
this._c = _c;
|
|
1133
|
-
}
|
|
1134
|
-
get value() {
|
|
1135
|
-
return this();
|
|
1136
|
-
}
|
|
1137
|
-
valueOf() {
|
|
1138
|
-
return this();
|
|
1139
|
-
}
|
|
1140
|
-
toString() {
|
|
1141
|
-
return "" + this();
|
|
1142
|
-
}
|
|
1143
|
-
toJSON() {
|
|
1144
|
-
return this();
|
|
1145
|
-
}
|
|
1146
|
-
peek() {
|
|
1147
|
-
return peek(this);
|
|
1148
|
-
}
|
|
1149
|
-
asReadonly() {
|
|
1150
|
-
return this;
|
|
1151
|
-
}
|
|
1152
|
-
withSet(set) {
|
|
1153
|
-
return Object.assign(new WritableImpl(this._c), { set });
|
|
1154
|
-
}
|
|
1155
|
-
*"uneventful.next"() {
|
|
1156
|
-
return yield (r) => {
|
|
1157
|
-
let seen = false, res;
|
|
1158
|
-
rule((stop) => {
|
|
1159
|
-
try {
|
|
1160
|
-
res = this();
|
|
1161
|
-
} catch (e) {
|
|
1162
|
-
stop();
|
|
1163
|
-
reject(r, e);
|
|
1164
|
-
}
|
|
1165
|
-
if (seen) {
|
|
1166
|
-
stop();
|
|
1167
|
-
resolve(r, res);
|
|
1168
|
-
}
|
|
1169
|
-
seen = true;
|
|
1170
|
-
});
|
|
1171
|
-
};
|
|
1172
|
-
}
|
|
1173
|
-
*"uneventful.until"() {
|
|
1174
|
-
return yield (r) => {
|
|
1175
|
-
let res;
|
|
1176
|
-
try {
|
|
1177
|
-
res = this();
|
|
1178
|
-
} catch (e) {
|
|
1179
|
-
reject(r, e);
|
|
1180
|
-
return;
|
|
1181
|
-
}
|
|
1182
|
-
if (res)
|
|
1183
|
-
return resolve(r, res);
|
|
1184
|
-
rule((stop) => {
|
|
1185
|
-
try {
|
|
1186
|
-
res = this();
|
|
1187
|
-
} catch (e) {
|
|
1188
|
-
stop();
|
|
1189
|
-
reject(r, e);
|
|
1190
|
-
}
|
|
1191
|
-
if (res) {
|
|
1192
|
-
stop();
|
|
1193
|
-
resolve(r, res);
|
|
1194
|
-
}
|
|
1195
|
-
});
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
class WritableImpl extends SignalImpl {
|
|
1200
|
-
constructor() {
|
|
1201
|
-
super(...arguments);
|
|
1202
|
-
this.set = (val) => {
|
|
1203
|
-
this._c.setValue(val, false);
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
get value() {
|
|
1207
|
-
return this();
|
|
1208
|
-
}
|
|
1209
|
-
set value(val) {
|
|
1210
|
-
this.set(val);
|
|
1211
|
-
}
|
|
1212
|
-
asReadonly() {
|
|
1213
|
-
return new SignalImpl(this._c);
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
class ConfigurableImpl extends WritableImpl {
|
|
1217
|
-
setf(expr) {
|
|
1218
|
-
this._c.setCalc(expr);
|
|
1219
|
-
return this;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
function value(val) {
|
|
1223
|
-
const cell = Cell.mkValue(val);
|
|
1224
|
-
return new ConfigurableImpl(cell);
|
|
1225
|
-
}
|
|
1226
|
-
function cached(compute, initVal) {
|
|
1227
|
-
if (compute instanceof SignalImpl)
|
|
1228
|
-
return compute;
|
|
1229
|
-
return new SignalImpl(
|
|
1230
|
-
compute.length ? Cell.mkStream(compute, initVal) : Cell.mkCached(compute)
|
|
1231
|
-
);
|
|
1232
|
-
}
|
|
1233
|
-
function peek(fn, ...args) {
|
|
1234
|
-
if (!current.cell)
|
|
1235
|
-
return fn(...args);
|
|
1236
|
-
const old = swapCtx(makeCtx(current.job));
|
|
1237
|
-
try {
|
|
1238
|
-
return fn.apply(null, args);
|
|
1239
|
-
} finally {
|
|
1240
|
-
freeCtx(swapCtx(old));
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
function recalcWhen(fnOrKey, fn) {
|
|
1244
|
-
current.cell?.recalcWhen(fnOrKey, fn);
|
|
1245
|
-
}
|
|
1246
|
-
function action(fn, _ctx, desc) {
|
|
1247
|
-
if (desc)
|
|
1248
|
-
return { ...desc, value: action(desc.value) };
|
|
1249
|
-
return function() {
|
|
1250
|
-
if (!current.cell)
|
|
1251
|
-
return fn.apply(this, arguments);
|
|
1252
|
-
const old = swapCtx(makeCtx(current.job));
|
|
1253
|
-
try {
|
|
1254
|
-
return fn.apply(this, arguments);
|
|
1255
|
-
} finally {
|
|
1256
|
-
freeCtx(swapCtx(old));
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
function must(cleanup) {
|
|
1262
|
-
return getJob().must(cleanup);
|
|
1263
|
-
}
|
|
1264
|
-
function start(init, fn) {
|
|
1265
|
-
return getJob().start(init, fn);
|
|
1266
|
-
}
|
|
1267
|
-
function isJobActive() {
|
|
1268
|
-
return !!current.job;
|
|
1269
|
-
}
|
|
1270
|
-
const timers = /* @__PURE__ */ new WeakMap();
|
|
1271
|
-
function timeout(ms = 0, job = getJob()) {
|
|
1272
|
-
let timer = timers.get(job);
|
|
1273
|
-
if (timer) {
|
|
1274
|
-
clearTimeout(timer);
|
|
1275
|
-
} else if (timer === void 0 && !job.result()) {
|
|
1276
|
-
job.must(timeout.bind(null, 0, job));
|
|
1277
|
-
}
|
|
1278
|
-
if (job.result()) {
|
|
1279
|
-
timers.delete(job);
|
|
1280
|
-
} else if (ms) {
|
|
1281
|
-
timers.set(job, setTimeout(() => {
|
|
1282
|
-
timers.set(job, null);
|
|
1283
|
-
job.end();
|
|
1284
|
-
}, ms));
|
|
1285
|
-
} else {
|
|
1286
|
-
timers.set(job, null);
|
|
1287
|
-
}
|
|
1288
|
-
return job;
|
|
1289
|
-
}
|
|
1290
|
-
const abortSignals = /* @__PURE__ */ new WeakMap();
|
|
1291
|
-
function abortSignal(job = getJob()) {
|
|
1292
|
-
let signal = abortSignals.get(job);
|
|
1293
|
-
if (!signal) {
|
|
1294
|
-
const ctrl = new AbortController();
|
|
1295
|
-
signal = ctrl.signal;
|
|
1296
|
-
job.do(() => {
|
|
1297
|
-
abortSignals.set(job, null);
|
|
1298
|
-
ctrl.abort();
|
|
1299
|
-
});
|
|
1300
|
-
abortSignals.set(job, signal);
|
|
1301
|
-
if (job.result())
|
|
1302
|
-
ctrl.abort();
|
|
1303
|
-
}
|
|
1304
|
-
return signal;
|
|
1305
|
-
}
|
|
1306
|
-
function restarting(task2) {
|
|
1307
|
-
const outer = getJob(), inner = makeJob(outer), { end } = inner;
|
|
1308
|
-
task2 ||= (f) => {
|
|
1309
|
-
inner.must(f());
|
|
1310
|
-
};
|
|
1311
|
-
inner.asyncCatch((e) => outer.asyncThrow(e));
|
|
1312
|
-
return function() {
|
|
1313
|
-
inner.restart().must(outer.release(end));
|
|
1314
|
-
const old = swapCtx(makeCtx(inner));
|
|
1315
|
-
try {
|
|
1316
|
-
return task2.apply(this, arguments);
|
|
1317
|
-
} catch (e) {
|
|
1318
|
-
inner.restart();
|
|
1319
|
-
throw e;
|
|
1320
|
-
} finally {
|
|
1321
|
-
freeCtx(swapCtx(old));
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
function task(fn, _ctx, desc) {
|
|
1326
|
-
if (desc)
|
|
1327
|
-
return { ...desc, value: task(desc.value) };
|
|
1328
|
-
return function(...args) {
|
|
1329
|
-
return start(() => fn.apply(this, args));
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
23
|
function emitter() {
|
|
1334
24
|
const emit = mockSource();
|
|
1335
25
|
emit.source = share(emit.source);
|
|
@@ -1523,7 +213,7 @@ function share(source) {
|
|
|
1523
213
|
function* each(src) {
|
|
1524
214
|
let yielded = false, waiter;
|
|
1525
215
|
const result = { value: { item: void 0, next: next2 }, done: false };
|
|
1526
|
-
const t = throttle(), conn =
|
|
216
|
+
const t = throttle(), conn = connect(src, (v) => {
|
|
1527
217
|
t.pause();
|
|
1528
218
|
if (!waiter || conn.result())
|
|
1529
219
|
return;
|
|
@@ -1568,38 +258,12 @@ function* each(src) {
|
|
|
1568
258
|
}
|
|
1569
259
|
}
|
|
1570
260
|
}
|
|
1571
|
-
function until(source) {
|
|
1572
|
-
return callOrWait(source, "uneventful.until", waitTruthy, recache);
|
|
1573
|
-
}
|
|
1574
|
-
function recache(s) {
|
|
1575
|
-
return until(cached(s));
|
|
1576
|
-
}
|
|
1577
|
-
function waitTruthy(job, v) {
|
|
1578
|
-
v && job.return(v);
|
|
1579
|
-
}
|
|
1580
261
|
function next(source) {
|
|
1581
262
|
return callOrWait(source, "uneventful.next", waitAny, mustBeSourceOrSignal);
|
|
1582
263
|
}
|
|
1583
264
|
function waitAny(job, v) {
|
|
1584
265
|
job.return(v);
|
|
1585
266
|
}
|
|
1586
|
-
function callOrWait(source, method, handler, noArgs) {
|
|
1587
|
-
if (source && isFunction(source[method]))
|
|
1588
|
-
return source[method]();
|
|
1589
|
-
if (isFunction(source))
|
|
1590
|
-
return (source.length === 0 ? noArgs(source) : false) || start((job) => {
|
|
1591
|
-
connect(source, (v) => handler(job, v)).do((r) => {
|
|
1592
|
-
if (isValue(r))
|
|
1593
|
-
job.throw(new Error("Stream ended"));
|
|
1594
|
-
else if (isError(r))
|
|
1595
|
-
job.throw(markHandled(r));
|
|
1596
|
-
});
|
|
1597
|
-
});
|
|
1598
|
-
mustBeSourceOrSignal();
|
|
1599
|
-
}
|
|
1600
|
-
function mustBeSourceOrSignal() {
|
|
1601
|
-
throw new TypeError("not a source or signal");
|
|
1602
|
-
}
|
|
1603
267
|
function forEach(src, sink, inlet) {
|
|
1604
268
|
if (isFunction(sink))
|
|
1605
269
|
return start((j) => {
|
|
@@ -1609,6 +273,9 @@ function forEach(src, sink, inlet) {
|
|
|
1609
273
|
sink = src;
|
|
1610
274
|
return (src2) => forEach(src2, sink, inlet);
|
|
1611
275
|
}
|
|
276
|
+
function recalcWhen(fnOrKey, fn) {
|
|
277
|
+
current.cell?.recalcWhen(fnOrKey, fn);
|
|
278
|
+
}
|
|
1612
279
|
|
|
1613
280
|
function concat(sources) {
|
|
1614
281
|
return concatAll(fromIterable(sources));
|
|
@@ -1768,5 +435,5 @@ function takeWhile(condition) {
|
|
|
1768
435
|
};
|
|
1769
436
|
}
|
|
1770
437
|
|
|
1771
|
-
export {
|
|
438
|
+
export { IsStream, backpressure, concat, concatAll, concatMap, connect, defer, detached, each, emitter, empty, filter, forEach, fromAsyncIterable, fromDomEvent, fromIterable, fromPromise, fromSubscribe, fromValue, fulfillPromise, getJob, interval, isCancel, isError, isUnhandled, isValue, lazy, map, markHandled, merge, mergeAll, mergeMap, mockSource, must, never, next, noop, recalcWhen, rejecter, resolve, resolver, restarting, share, skip, skipUntil, skipWhile, slack, sleep, start, switchAll, switchMap, take, takeUntil, takeWhile, throttle, to };
|
|
1772
439
|
//# sourceMappingURL=mod.mjs.map
|