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.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { J as Job, C as CleanupFn, Y as Yielding, S as Source, D as DisposeFn, a as Stream, B as Backpressure, T as Transformer, b as Sink, O as OptionalCleanup, c as StartFn, d as StartObj, A as AnyFunction } from './types-N2ua11te.js';
|
|
2
|
+
export { e as AsyncStart, z as CancelError, m as CancelResult, K as Connection, E as ErrorResult, H as HandledError, I as Inlet, M as IsStream, g as JobIterator, o as JobResult, N as Nothing, P as PlainFunction, i as RecalcSource, R as Request, L as SignalSource, h as Suspend, f as SyncStart, G as Throttle, U as UnhandledError, V as ValueResult, F as backpressure, Z as compose, Q as connect, x as fulfillPromise, w as getResult, _ as into, p as isCancel, s as isError, u as isHandled, t as isUnhandled, q as isValue, v as markHandled, n as noop, X as pipe, y as propagateResult, j as reject, l as rejecter, r as resolve, k as resolver, W as throttle } from './types-N2ua11te.js';
|
|
3
|
+
export { a as Each, E as EachResult, N as NextMethod, U as UntilMethod, e as each, f as forEach, n as next, r as recalcWhen } from './sinks-kEzJo6Hc.js';
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Invoke a no-argument function as a microtask, using queueMicrotask or Promise.resolve().then()
|
|
3
7
|
*
|
|
@@ -5,974 +9,6 @@
|
|
|
5
9
|
*/
|
|
6
10
|
declare let defer: (cb: () => any) => void;
|
|
7
11
|
|
|
8
|
-
/**
|
|
9
|
-
* Resolve a {@link Request} with a value.
|
|
10
|
-
*
|
|
11
|
-
* (For a curried version, see {@link resolver}.)
|
|
12
|
-
*
|
|
13
|
-
* @category Requests and Results
|
|
14
|
-
*/
|
|
15
|
-
declare function resolve<T>(request: Request<T>, val: T): void;
|
|
16
|
-
/**
|
|
17
|
-
* Reject a {@link Request} with a reason.
|
|
18
|
-
*
|
|
19
|
-
* (For a curried version, see {@link rejecter}.)
|
|
20
|
-
*
|
|
21
|
-
* @category Requests and Results
|
|
22
|
-
*/
|
|
23
|
-
declare function reject(request: Request<any>, reason: any): void;
|
|
24
|
-
/**
|
|
25
|
-
* Create a callback that will resolve the given {@link Request} with a value.
|
|
26
|
-
*
|
|
27
|
-
* @category Requests and Results
|
|
28
|
-
*/
|
|
29
|
-
declare function resolver<T>(request: Request<T>): (val: T) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Create a callback that will reject the given {@link Request} with a reason.
|
|
32
|
-
*
|
|
33
|
-
* @category Requests and Results
|
|
34
|
-
*/
|
|
35
|
-
declare function rejecter(request: Request<any>): (err: any) => void;
|
|
36
|
-
/**
|
|
37
|
-
* A function that does nothing and returns void.
|
|
38
|
-
*
|
|
39
|
-
* @category Stream Consumers
|
|
40
|
-
*/
|
|
41
|
-
declare function noop(): void;
|
|
42
|
-
/**
|
|
43
|
-
* An {@link ErrorResult} that hasn't yet been "handled" (by being passed to an
|
|
44
|
-
* error-specific handler, converted to a promise, given to {@link markHandled},
|
|
45
|
-
* etc.)
|
|
46
|
-
*
|
|
47
|
-
* @category Types and Interfaces
|
|
48
|
-
*/
|
|
49
|
-
type UnhandledError = {
|
|
50
|
-
op: "throw";
|
|
51
|
-
val: undefined;
|
|
52
|
-
err: any;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* An {@link ErrorResult} that has been marked "handled" (by being passed to an
|
|
56
|
-
* error-specific handler, converted to a promise, given to {@link markHandled},
|
|
57
|
-
* etc.)
|
|
58
|
-
*
|
|
59
|
-
* @category Types and Interfaces
|
|
60
|
-
*/
|
|
61
|
-
type HandledError = {
|
|
62
|
-
op: "throw";
|
|
63
|
-
val: null;
|
|
64
|
-
err: any;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* A result passed to a job's cleanup callbacks, or supplied by its
|
|
68
|
-
* .{@link Job.result result}() method.
|
|
69
|
-
*
|
|
70
|
-
* You can inspect a JobResult using functions like {@link isCancel}(),
|
|
71
|
-
* {@link isError}(), and {@link isValue}(). {@link getResult}() can be used to
|
|
72
|
-
* unwrap the value or throw the error.
|
|
73
|
-
*
|
|
74
|
-
* @category Types and Interfaces
|
|
75
|
-
*/
|
|
76
|
-
type JobResult<T> = ValueResult<T> | ErrorResult | CancelResult;
|
|
77
|
-
/**
|
|
78
|
-
* A {@link JobResult} that indicates the job was canceled by its creator (via
|
|
79
|
-
* end() or restart()).
|
|
80
|
-
*
|
|
81
|
-
* @category Types and Interfaces
|
|
82
|
-
*/
|
|
83
|
-
type CancelResult = {
|
|
84
|
-
op: "cancel";
|
|
85
|
-
val: undefined;
|
|
86
|
-
err: undefined;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* The {@link JobResult} used to indicate a canceled job.
|
|
90
|
-
*
|
|
91
|
-
* @category Requests and Results
|
|
92
|
-
*/
|
|
93
|
-
declare const CancelResult: Readonly<CancelResult>;
|
|
94
|
-
/**
|
|
95
|
-
* A {@link JobResult} that indicates the job was ended via a return() value.
|
|
96
|
-
*
|
|
97
|
-
* @category Types and Interfaces
|
|
98
|
-
*/
|
|
99
|
-
type ValueResult<T> = {
|
|
100
|
-
op: "next";
|
|
101
|
-
val: T;
|
|
102
|
-
err: undefined;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Create a {@link ValueResult} from a value
|
|
106
|
-
*
|
|
107
|
-
* @category Requests and Results
|
|
108
|
-
*/
|
|
109
|
-
declare function ValueResult<T>(val: T): ValueResult<T>;
|
|
110
|
-
/**
|
|
111
|
-
* A {@link JobResult} that indicates the job was ended via a throw() or other
|
|
112
|
-
* error.
|
|
113
|
-
*
|
|
114
|
-
* @category Types and Interfaces
|
|
115
|
-
*/
|
|
116
|
-
type ErrorResult = UnhandledError | HandledError;
|
|
117
|
-
/**
|
|
118
|
-
* Create an {@link ErrorResult} from an error
|
|
119
|
-
*
|
|
120
|
-
* @category Requests and Results
|
|
121
|
-
*/
|
|
122
|
-
declare function ErrorResult(err: any): UnhandledError;
|
|
123
|
-
/**
|
|
124
|
-
* Returns true if the given result is a {@link CancelResult}.
|
|
125
|
-
*
|
|
126
|
-
* @category Requests and Results
|
|
127
|
-
*/
|
|
128
|
-
declare function isCancel(res: JobResult<any> | undefined): res is CancelResult;
|
|
129
|
-
/**
|
|
130
|
-
* Returns true if the given result is a {@link ValueResult}.
|
|
131
|
-
*
|
|
132
|
-
* @category Requests and Results
|
|
133
|
-
*/
|
|
134
|
-
declare function isValue<T>(res: JobResult<T> | undefined): res is ValueResult<T>;
|
|
135
|
-
/**
|
|
136
|
-
* Returns true if the given result is a {@link ErrorResult}.
|
|
137
|
-
*
|
|
138
|
-
* @category Requests and Results
|
|
139
|
-
*/
|
|
140
|
-
declare function isError(res: JobResult<any> | undefined): res is ErrorResult;
|
|
141
|
-
/**
|
|
142
|
-
* Returns true if the given result is an {@link UnhandledError}.
|
|
143
|
-
*
|
|
144
|
-
* @category Requests and Results
|
|
145
|
-
*/
|
|
146
|
-
declare function isUnhandled(res: JobResult<any> | undefined): res is UnhandledError;
|
|
147
|
-
/**
|
|
148
|
-
* Returns true if the given result is a {@link HandledError} (an
|
|
149
|
-
* {@link ErrorResult} that has been touched by {@link markHandled}).
|
|
150
|
-
*
|
|
151
|
-
* @category Requests and Results
|
|
152
|
-
*/
|
|
153
|
-
declare function isHandled(res: JobResult<any> | undefined): res is HandledError;
|
|
154
|
-
/**
|
|
155
|
-
* Return the error of an {@link ErrorResult} and mark it as handled. The
|
|
156
|
-
* {@link ErrorResult} is mutated in-place to become a {@link HandledError}.
|
|
157
|
-
*
|
|
158
|
-
* @category Requests and Results
|
|
159
|
-
*/
|
|
160
|
-
declare function markHandled(res: ErrorResult): any;
|
|
161
|
-
/**
|
|
162
|
-
* Get the return value from a {@link JobResult}, throwing an appropriate error
|
|
163
|
-
* if the result isn't a {@link ValueResult}.
|
|
164
|
-
*
|
|
165
|
-
* @param res The job result you want to unwrap. Must not be undefined!
|
|
166
|
-
*
|
|
167
|
-
* @returns The value if the result is a {@link ValueResult}, or a thrown error
|
|
168
|
-
* if it's an {@link ErrorResult}. A {@link CancelError} is thrown if the job
|
|
169
|
-
* was canceled, or the error in the result is thrown.
|
|
170
|
-
*
|
|
171
|
-
* If the result is an error, it is marked as handled.
|
|
172
|
-
*
|
|
173
|
-
* @category Jobs
|
|
174
|
-
*/
|
|
175
|
-
declare function getResult<T>(res: JobResult<T>): T;
|
|
176
|
-
/**
|
|
177
|
-
* Fulfill a Promise from a {@link JobResult}
|
|
178
|
-
*
|
|
179
|
-
* If the result is a {@link CancelResult}, the promise is rejected with a
|
|
180
|
-
* {@link CancelError}. Otherwise it is resolved or rejected according to the
|
|
181
|
-
* state of the result.
|
|
182
|
-
*
|
|
183
|
-
* @param resolve A value-taking function (first arg to `new Promise` callback)
|
|
184
|
-
*
|
|
185
|
-
* @param reject An error-taking function (second arg to `new Promise` callback)
|
|
186
|
-
*
|
|
187
|
-
* @param res The job result you want to settle the promise with. An error will
|
|
188
|
-
* be thrown if it's undefined.
|
|
189
|
-
*
|
|
190
|
-
* If the result is an error, it is marked as handled.
|
|
191
|
-
*
|
|
192
|
-
* @category Requests and Results
|
|
193
|
-
*/
|
|
194
|
-
declare function fulfillPromise<T>(resolve: (v: T) => void, reject: (e: any) => void, res: JobResult<T>): void;
|
|
195
|
-
/**
|
|
196
|
-
* Propagate a {@link JobResult} to another job
|
|
197
|
-
*
|
|
198
|
-
* If the result is a {@link CancelResult}, the job will throw with a
|
|
199
|
-
* {@link CancelError}. Otherwise it is resolved or rejected according to the
|
|
200
|
-
* state of the result.
|
|
201
|
-
*
|
|
202
|
-
* @param job The job to terminate. If it's already ended, nothing changes: the
|
|
203
|
-
* result is not propagated and the error (if any) is not marked as handled.
|
|
204
|
-
*
|
|
205
|
-
* @param res The job result you want to settle the job with. An error will be
|
|
206
|
-
* thrown if it's undefined. If the result is an error, it is marked as
|
|
207
|
-
* handled.
|
|
208
|
-
*
|
|
209
|
-
* @category Requests and Results
|
|
210
|
-
*/
|
|
211
|
-
declare function propagateResult<T>(job: Job<T>, res: JobResult<T>): void;
|
|
212
|
-
/**
|
|
213
|
-
* Error thrown when waiting for a result from a job that is canceled.
|
|
214
|
-
*
|
|
215
|
-
* If you `await`, `yield *`, `.then()`, `.catch()`, {@link getResult}() or
|
|
216
|
-
* otherwise wait on the result of a job that is canceled, this is the type
|
|
217
|
-
* of error you'll get.
|
|
218
|
-
*
|
|
219
|
-
* @category Errors
|
|
220
|
-
*/
|
|
221
|
-
declare class CancelError extends Error {
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* A backpressure controller: returns true if downstream is ready to accept
|
|
226
|
-
* data.
|
|
227
|
-
*
|
|
228
|
-
* @param cb (optional) - a callback to run when the downstream consumer wishes
|
|
229
|
-
* to resume event production (i.e., when a sink calls
|
|
230
|
-
* {@link Throttle.resume}()). The callback is automatically unregistered when
|
|
231
|
-
* invoked, so the producer must re-register it after each call if it wishes to
|
|
232
|
-
* keep being called.
|
|
233
|
-
*
|
|
234
|
-
* @category Types and Interfaces
|
|
235
|
-
*/
|
|
236
|
-
type Backpressure = (cb?: () => any) => boolean;
|
|
237
|
-
/**
|
|
238
|
-
* Create a backpressure control function for the given connection
|
|
239
|
-
*
|
|
240
|
-
* @category Stream Producers
|
|
241
|
-
*/
|
|
242
|
-
declare function backpressure(inlet?: Inlet): Backpressure;
|
|
243
|
-
/**
|
|
244
|
-
* Control backpressure for listening streams. This interface is the API
|
|
245
|
-
* internal to the implementation of {@link backpressure}(). Unless you're
|
|
246
|
-
* implementing a backpressurable stream yourself, see the {@link Throttle}
|
|
247
|
-
* interface instead.
|
|
248
|
-
*
|
|
249
|
-
* @category Types and Interfaces
|
|
250
|
-
*/
|
|
251
|
-
interface Inlet {
|
|
252
|
-
/** Is the main connection open? (i.e. is the creating job not closed yet?) */
|
|
253
|
-
isOpen(): boolean;
|
|
254
|
-
/** Is the conduit currently ready to receive data? */
|
|
255
|
-
isReady(): boolean;
|
|
256
|
-
/**
|
|
257
|
-
* Register a callback to produce more data when the inlet is resumed
|
|
258
|
-
* (The callback is unregistered if the supplied job ends.)
|
|
259
|
-
*/
|
|
260
|
-
onReady(cb: () => any, job: Job): this;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Control backpressure for listening streams
|
|
264
|
-
*
|
|
265
|
-
* Obtain instances via {@link throttle}(), then pass them into the appropriate
|
|
266
|
-
* stream-consuming API. (e.g. {@link connect}).
|
|
267
|
-
*
|
|
268
|
-
* @category Types and Interfaces
|
|
269
|
-
*/
|
|
270
|
-
interface Throttle extends Inlet {
|
|
271
|
-
/** Set inlet status to "paused". */
|
|
272
|
-
pause(): void;
|
|
273
|
-
/**
|
|
274
|
-
* Un-pause, and iterate backpressure-able sources' onReady callbacks to
|
|
275
|
-
* resume sending immediately. (i.e., synchronously!)
|
|
276
|
-
*/
|
|
277
|
-
resume(): void;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* A Connection is a job that returns void when the connected stream ends
|
|
281
|
-
* itself. If the stream doesn't end itself (e.g. it's an event listener), the
|
|
282
|
-
* job will never return, and only end with a cancel or throw.
|
|
283
|
-
*
|
|
284
|
-
* @category Types and Interfaces
|
|
285
|
-
*/
|
|
286
|
-
type Connection = Job<void>;
|
|
287
|
-
/**
|
|
288
|
-
* A Source is a function that can be called to arrange for data to be
|
|
289
|
-
* produced and sent to a {@link Sink} function for consumption, until the
|
|
290
|
-
* associated {@link Connection} is closed (either by the source or the sink,
|
|
291
|
-
* e.g. if the sink doesn't want more data or the source has no more to send).
|
|
292
|
-
*
|
|
293
|
-
* If the source is a backpressurable stream, it can use the (optional) supplied
|
|
294
|
-
* inlet (usually a {@link throttle}()) to rate-limit its output.
|
|
295
|
-
*
|
|
296
|
-
* A producer function *must* return the special {@link IsStream} value, so
|
|
297
|
-
* TypeScript can tell what functions are usable as sources. (Otherwise any
|
|
298
|
-
* void function with no arguments would appear to be usable as a source!)
|
|
299
|
-
*
|
|
300
|
-
* @category Types and Interfaces
|
|
301
|
-
*/
|
|
302
|
-
interface Source<T> {
|
|
303
|
-
/** Subscribe sink to receive values */
|
|
304
|
-
(sink: Sink<T>, conn?: Connection, inlet?: Throttle | Inlet): typeof IsStream;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* An uneventful stream is either a {@link Source} or a {@link SignalSource}.
|
|
308
|
-
* (Signals actually implement the {@link Source} interface as an overload, but
|
|
309
|
-
* TypeScript gets confused about that sometimes, so we generally declare our
|
|
310
|
-
* stream *inputs* as `Stream<T>` and our stream *outputs* as {@link Source}, so
|
|
311
|
-
* that TypeScript knows what's what.
|
|
312
|
-
*
|
|
313
|
-
* @category Types and Interfaces
|
|
314
|
-
*/
|
|
315
|
-
type Stream<T> = Source<T> | SignalSource<T>;
|
|
316
|
-
/**
|
|
317
|
-
* The call signatures implemented by signals. (They can be used as sources, or
|
|
318
|
-
* called with no arguments to return a value.)
|
|
319
|
-
*
|
|
320
|
-
* This type is needed because TypeScript won't infer the overloads of
|
|
321
|
-
* {@link Signal} correctly otherwise. (Specifically, it won't allow it to be
|
|
322
|
-
* used as a zero-agument function.)
|
|
323
|
-
*
|
|
324
|
-
* @category Types and Interfaces
|
|
325
|
-
*/
|
|
326
|
-
type SignalSource<T> = Source<T> & {
|
|
327
|
-
/** A signal object can be called to get its current value */
|
|
328
|
-
(): T;
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* A specially-typed string used to verify that a function supports uneventful's
|
|
332
|
-
* streaming protocol. Return it from a function to implement the
|
|
333
|
-
* {@link Source} type.
|
|
334
|
-
*
|
|
335
|
-
* @category Types and Interfaces
|
|
336
|
-
*/
|
|
337
|
-
declare const IsStream: "uneventful/is-stream";
|
|
338
|
-
/**
|
|
339
|
-
* A `Sink` is a function that receives data from a {@link Stream}.
|
|
340
|
-
*
|
|
341
|
-
* @category Types and Interfaces
|
|
342
|
-
*/
|
|
343
|
-
type Sink<T> = (val: T) => void;
|
|
344
|
-
/**
|
|
345
|
-
* A `Transformer` is a function that takes one stream and returns another,
|
|
346
|
-
* possibly one that produces data of a different type. Most operator functions
|
|
347
|
-
* return a transformer, allowing them to be combined via {@link pipe}().
|
|
348
|
-
*
|
|
349
|
-
* @category Types and Interfaces
|
|
350
|
-
*/
|
|
351
|
-
type Transformer<T, V = T> = (input: Stream<T>) => Source<V>;
|
|
352
|
-
/**
|
|
353
|
-
* Subscribe a sink to a stream, returning a nested job. (Shorthand for
|
|
354
|
-
* {@link getJob}().{@link Job.connect connect}(...).)
|
|
355
|
-
*
|
|
356
|
-
* @param src An event source or signal
|
|
357
|
-
* @param sink A callback that will receive the events
|
|
358
|
-
* @param inlet Optional - a {@link throttle}() to control backpressure
|
|
359
|
-
*
|
|
360
|
-
* @returns A job that can be aborted to end the subscription, and which will
|
|
361
|
-
* end naturally (with a void return or error) if the stream ends itself.
|
|
362
|
-
*
|
|
363
|
-
* @category Stream Consumers
|
|
364
|
-
*/
|
|
365
|
-
declare function connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Throttle | Inlet): Connection;
|
|
366
|
-
/**
|
|
367
|
-
* Create a backpressure controller for a stream. Pass it to one or more
|
|
368
|
-
* sources you're connecting to, and if they support backpressure they'll
|
|
369
|
-
* respond when you call its .pause() and .resume() methods.
|
|
370
|
-
*
|
|
371
|
-
* @param job - Optional: a job that controls readiness. (The throttle will
|
|
372
|
-
* pause indefinitely when the job ends.) Defaults to the currently-active job,
|
|
373
|
-
* but unlike most such defaults, it won't throw if no job is active.
|
|
374
|
-
*
|
|
375
|
-
* @category Stream Consumers
|
|
376
|
-
*/
|
|
377
|
-
declare function throttle(job?: Job): Throttle;
|
|
378
|
-
/**
|
|
379
|
-
* Pipe a stream (or anything else) through a series of single-argument
|
|
380
|
-
* functions/operators
|
|
381
|
-
*
|
|
382
|
-
* e.g. the following creates a stream that outputs 4 and then 6:
|
|
383
|
-
*
|
|
384
|
-
* ```ts
|
|
385
|
-
* pipe(fromIterable([1,2,3,4]), skip(1), take(2), map(x => x*2))
|
|
386
|
-
* ```
|
|
387
|
-
*
|
|
388
|
-
* The first argument to pipe() can be any value, but all other arguments must
|
|
389
|
-
* be functions. The value is passed to the first function, and then the result
|
|
390
|
-
* is passed to the next function in turn, until all provided functions have
|
|
391
|
-
* been called with the result of the previous function. The return value is
|
|
392
|
-
* the last result, or the original value if no functions were given.
|
|
393
|
-
*
|
|
394
|
-
* The underlying implementation of pipe() works with any number of arguments,
|
|
395
|
-
* but due to TypeScript limitations we only have typing defined for a max of 9
|
|
396
|
-
* functions (10 arguments total). If you need more than 9 functions, you can
|
|
397
|
-
* stack some of them with {@link compose}(), e.g.:
|
|
398
|
-
*
|
|
399
|
-
* ```typescript
|
|
400
|
-
* pipe(
|
|
401
|
-
* aStream,
|
|
402
|
-
* compose(op1, op2, ...),
|
|
403
|
-
* compose(op10, op11, ...),
|
|
404
|
-
* compose(op19, ...),
|
|
405
|
-
* ...
|
|
406
|
-
* )
|
|
407
|
-
* ```
|
|
408
|
-
*
|
|
409
|
-
* @category Stream Operators
|
|
410
|
-
*/
|
|
411
|
-
declare function pipe<A, B, C, D, E, F, G, H, I, J>(input: A, ...fns: Chain9<A, J, B, C, D, E, F, G, H, I>): J;
|
|
412
|
-
declare function pipe<A, B, C, D, E, F, G, H, I>(input: A, ...fns: Chain8<A, I, B, C, D, E, F, G, H>): I;
|
|
413
|
-
declare function pipe<A, B, C, D, E, F, G, H>(input: A, ...fns: Chain7<A, H, B, C, D, E, F, G>): H;
|
|
414
|
-
declare function pipe<A, B, C, D, E, F, G>(input: A, ...fns: Chain6<A, G, B, C, D, E, F>): G;
|
|
415
|
-
declare function pipe<A, B, C, D, E, F>(input: A, ...fns: Chain5<A, F, B, C, D, E>): F;
|
|
416
|
-
declare function pipe<A, B, C, D, E>(input: A, ...fns: Chain4<A, E, B, C, D>): E;
|
|
417
|
-
declare function pipe<A, B, C, D>(input: A, ...fns: Chain3<A, D, B, C>): D;
|
|
418
|
-
declare function pipe<A, B, C>(input: A, ...fns: Chain2<A, C, B>): C;
|
|
419
|
-
declare function pipe<A, B>(input: A, ...fns: Chain1<A, B>): B;
|
|
420
|
-
declare function pipe<A>(input: A): A;
|
|
421
|
-
declare function pipe(input: any, ...fns: Array<(v: any) => any>): any;
|
|
422
|
-
/**
|
|
423
|
-
* Compose a series of single-argument functions/operators in application order.
|
|
424
|
-
* (This is basically a deferred version of {@link pipe}().) For example:
|
|
425
|
-
*
|
|
426
|
-
* ```ts
|
|
427
|
-
* const func = compose(skip(1), take(2), map(x => x*2));
|
|
428
|
-
* const stream_4_6 = func(fromIterable([1,2,3,4])); // stream that outputs 4, 6
|
|
429
|
-
* ```
|
|
430
|
-
*
|
|
431
|
-
* As with `pipe()`, the declared typings only support composing up to 9
|
|
432
|
-
* functions at once; if you need more you'll need to nest calls to `compose()`
|
|
433
|
-
* (i.e. passing the result of a `compose()` as an argument to another
|
|
434
|
-
* `compose()` call.)
|
|
435
|
-
*
|
|
436
|
-
* @returns A function taking the same type as the first input function,
|
|
437
|
-
* returning the same type as the last input function.
|
|
438
|
-
*
|
|
439
|
-
* @category Stream Operators
|
|
440
|
-
*/
|
|
441
|
-
declare function compose<A, B, C, D, E, F, G, H, I, J>(...fns: Chain9<A, J, B, C, D, E, F, G, H, I>): (a: A) => J;
|
|
442
|
-
declare function compose<A, B, C, D, E, F, G, H, I>(...fns: Chain8<A, I, B, C, D, E, F, G, H>): (a: A) => I;
|
|
443
|
-
declare function compose<A, B, C, D, E, F, G, H>(...fns: Chain7<A, H, B, C, D, E, F, G>): (a: A) => H;
|
|
444
|
-
declare function compose<A, B, C, D, E, F, G>(...fns: Chain6<A, G, B, C, D, E, F>): (a: A) => G;
|
|
445
|
-
declare function compose<A, B, C, D, E, F>(...fns: Chain5<A, F, B, C, D, E>): (a: A) => F;
|
|
446
|
-
declare function compose<A, B, C, D, E>(...fns: Chain4<A, E, B, C, D>): (a: A) => E;
|
|
447
|
-
declare function compose<A, B, C, D>(...fns: Chain3<A, D, B, C>): (a: A) => D;
|
|
448
|
-
declare function compose<A, B, C>(...fns: Chain2<A, C, B>): (a: A) => C;
|
|
449
|
-
declare function compose<A, B>(...fns: Chain1<A, B>): (a: A) => B;
|
|
450
|
-
declare function compose<A>(): (a: A) => A;
|
|
451
|
-
type Chain1<A, R> = [(v: A) => R];
|
|
452
|
-
type Chain2<A, R, B> = [...Chain1<A, B>, ...Chain1<B, R>];
|
|
453
|
-
type Chain3<A, R, B, C> = [...Chain1<A, B>, ...Chain2<B, R, C>];
|
|
454
|
-
type Chain4<A, R, B, C, D> = [...Chain1<A, B>, ...Chain3<B, R, C, D>];
|
|
455
|
-
type Chain5<A, R, B, C, D, E> = [...Chain1<A, B>, ...Chain4<B, R, C, D, E>];
|
|
456
|
-
type Chain6<A, R, B, C, D, E, F> = [...Chain1<A, B>, ...Chain5<B, R, C, D, E, F>];
|
|
457
|
-
type Chain7<A, R, B, C, D, E, F, G> = [...Chain1<A, B>, ...Chain6<B, R, C, D, E, F, G>];
|
|
458
|
-
type Chain8<A, R, B, C, D, E, F, G, H> = [...Chain1<A, B>, ...Chain7<B, R, C, D, E, F, G, H>];
|
|
459
|
-
type Chain9<A, R, B, C, D, E, F, G, H, I> = [...Chain1<A, B>, ...Chain8<B, R, C, D, E, F, G, H, I>];
|
|
460
|
-
/**
|
|
461
|
-
* Pass subscriber into a stream (or any arguments into any other function).
|
|
462
|
-
*
|
|
463
|
-
* This utility is mainly here for uses like:
|
|
464
|
-
*
|
|
465
|
-
* - `pipe(src, into(sink))`,
|
|
466
|
-
* - `pipe(src, into(sink, conn))`,
|
|
467
|
-
* - `pipe(src, into(restarting(sink)))`, etc.
|
|
468
|
-
*
|
|
469
|
-
* but can also be used for argument currying generally.
|
|
470
|
-
*
|
|
471
|
-
* @param args The arguments to pass to the stream (or other function)
|
|
472
|
-
*
|
|
473
|
-
* @returns a function that takes another function and calls it with the given args.
|
|
474
|
-
*
|
|
475
|
-
* @category Stream Consumers
|
|
476
|
-
*/
|
|
477
|
-
declare function into<In extends any[], Out>(...args: In): (src: (...args: In) => Out) => Out;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* An undefined or null value
|
|
481
|
-
*
|
|
482
|
-
* @category Types and Interfaces
|
|
483
|
-
*/
|
|
484
|
-
type Nothing = undefined | null | void;
|
|
485
|
-
/**
|
|
486
|
-
* A function without a `this`
|
|
487
|
-
*
|
|
488
|
-
* @category Types and Interfaces
|
|
489
|
-
*/
|
|
490
|
-
type PlainFunction = (this: void, ...args: any[]) => any;
|
|
491
|
-
/**
|
|
492
|
-
* Any function
|
|
493
|
-
*
|
|
494
|
-
* @category Types and Interfaces
|
|
495
|
-
*/
|
|
496
|
-
type AnyFunction = (...args: any[]) => any;
|
|
497
|
-
/**
|
|
498
|
-
* A cleanup function is a callback invoked when a job is ended or restarted.
|
|
499
|
-
* It receives a result that indicates whether the job ended itself with a return
|
|
500
|
-
* value or error, or was canceled/restarted by its creator.
|
|
501
|
-
*
|
|
502
|
-
* @category Types and Interfaces
|
|
503
|
-
*/
|
|
504
|
-
type CleanupFn<T = any> = (res: JobResult<T>) => unknown;
|
|
505
|
-
/**
|
|
506
|
-
* A function that can be called to dispose of something or unsubscribe
|
|
507
|
-
* something. It's called without arguments and returns void.
|
|
508
|
-
*
|
|
509
|
-
* @category Types and Interfaces
|
|
510
|
-
*/
|
|
511
|
-
type DisposeFn = () => void;
|
|
512
|
-
/**
|
|
513
|
-
* An optional cleanup parameter or return.
|
|
514
|
-
*
|
|
515
|
-
* @category Types and Interfaces
|
|
516
|
-
*/
|
|
517
|
-
type OptionalCleanup<T = any> = CleanupFn<T> | Nothing;
|
|
518
|
-
/**
|
|
519
|
-
* An asynchronous start function is called immediately in the new job and must
|
|
520
|
-
* return a {@link StartObj}, such as a job, generator, or promise. If a job or
|
|
521
|
-
* promise is returned, it will be awaited and its result used to asynchronously
|
|
522
|
-
* set the result of the returned job.
|
|
523
|
-
*
|
|
524
|
-
* If a generator is returned, it will be run asynchronously, in the context of
|
|
525
|
-
* the newly-started job. Any result it returns or error it throws will be
|
|
526
|
-
* treated as the result of the job. If the job is canceled, the iterator's
|
|
527
|
-
* `.return()` method will be called to abort it (thereby running any
|
|
528
|
-
* try-finally clauses in the generator), and the result of the call will be
|
|
529
|
-
* otherwise ignored.
|
|
530
|
-
*
|
|
531
|
-
* @template T The type the job will end up returning
|
|
532
|
-
* @template This The type of `this` the function accepts, if using two-argument
|
|
533
|
-
* start(). Defaults to void (for one-argument start()).
|
|
534
|
-
*
|
|
535
|
-
* @category Types and Interfaces
|
|
536
|
-
*/
|
|
537
|
-
type AsyncStart<T, This = void> = (this: This, job: Job<T>) => StartObj<T>;
|
|
538
|
-
/**
|
|
539
|
-
* A synchronous start function returns void or a {@link CleanupFn}. It runs
|
|
540
|
-
* immediately and gets passed the newly created job as its first argument.
|
|
541
|
-
*
|
|
542
|
-
* @template T The type the job will end up returning
|
|
543
|
-
* @template This The type of `this` the function accepts, if using two-argument
|
|
544
|
-
* start(). Defaults to void (for one-argument start()).
|
|
545
|
-
*
|
|
546
|
-
* @category Types and Interfaces
|
|
547
|
-
*/
|
|
548
|
-
type SyncStart<T, This = void> = (this: This, job: Job<T>) => OptionalCleanup;
|
|
549
|
-
/**
|
|
550
|
-
* A synchronous or asynchronous initializing function for use with the
|
|
551
|
-
* {@link start}() function or a job's {@link Job.start .start}() method.
|
|
552
|
-
*
|
|
553
|
-
* @template T The type the job will end up returning
|
|
554
|
-
* @template This The type of `this` the function accepts, if using two-argument
|
|
555
|
-
* start(). Defaults to void (for one-argument start()).
|
|
556
|
-
*
|
|
557
|
-
* @category Types and Interfaces
|
|
558
|
-
*/
|
|
559
|
-
type StartFn<T, This = void> = AsyncStart<T, This> | SyncStart<T, This>;
|
|
560
|
-
/**
|
|
561
|
-
* An object that can be passed as a single argument to {@link start}() or a
|
|
562
|
-
* job's {@link Job.start .start}() method, such as a job, generator, or
|
|
563
|
-
* promise.
|
|
564
|
-
*
|
|
565
|
-
* @category Types and Interfaces
|
|
566
|
-
*/
|
|
567
|
-
type StartObj<T> = Yielding<T> | Promise<T> | PromiseLike<T>;
|
|
568
|
-
/**
|
|
569
|
-
* A cancellable asynchronous operation with automatic resource cleanup.
|
|
570
|
-
*
|
|
571
|
-
* You can add cleanup callbacks to a job via {@link must}() or its
|
|
572
|
-
* .{@link must}() method. When the job is ended or canceled, the callbacks
|
|
573
|
-
* are (synchronously) run in reverse order -- a bit like a delayed and
|
|
574
|
-
* distributed collection of `finally` blocks.
|
|
575
|
-
*
|
|
576
|
-
* Jobs implement the Promise interface (then, catch, and finally) so they can
|
|
577
|
-
* be passed to Promise-using APIs or awaited by async functions. They also
|
|
578
|
-
* implement {@link Yielding}, so you can await their results from a
|
|
579
|
-
* {@link start}() using `yield *`. They also have
|
|
580
|
-
* {@link Job.return \.return()} and {@link Job.throw \.throw()} methods so
|
|
581
|
-
* you can end a job with a result or error.
|
|
582
|
-
*
|
|
583
|
-
* Most jobs, however, are not intended to produce results, and are merely
|
|
584
|
-
* canceled (using {@link Job.end \.end()} or
|
|
585
|
-
* {@link Job.restart \.restart()}).
|
|
586
|
-
*
|
|
587
|
-
* Jobs can be created and accessed using {@link start}(),
|
|
588
|
-
* {@link detached}.start(), {@link makeJob}(), and {@link getJob}().
|
|
589
|
-
*
|
|
590
|
-
* @category Types and Interfaces
|
|
591
|
-
*/
|
|
592
|
-
interface Job<T = any> extends Yielding<T>, Promise<T> {
|
|
593
|
-
/**
|
|
594
|
-
* The result of the job (canceled, returned value, or error), or
|
|
595
|
-
* undefined if the job isn't finished.
|
|
596
|
-
*
|
|
597
|
-
* @category Obtaining Results
|
|
598
|
-
*/
|
|
599
|
-
result(): JobResult<T> | undefined;
|
|
600
|
-
/**
|
|
601
|
-
* Add a cleanup callback to be run when the job is ended or restarted.
|
|
602
|
-
* (Non-function values are ignored.) If the job has already ended, the
|
|
603
|
-
* callback will be invoked asynchronously in the next microtask. Cleanup
|
|
604
|
-
* functions are run in LIFO order, after any {@link Job.release}()
|
|
605
|
-
* callbacks (including those of the job's children), but before any
|
|
606
|
-
* {@link Job.do}() callbacks are run for the same job.
|
|
607
|
-
*
|
|
608
|
-
* Generally speaking, this method is used within a job to arrange for used
|
|
609
|
-
* resources to be cleaned up or to undo other state that was only supposed
|
|
610
|
-
* to be active while the job was running.
|
|
611
|
-
*
|
|
612
|
-
* @category Resource Tracking
|
|
613
|
-
*/
|
|
614
|
-
must(cleanup?: OptionalCleanup<T>): this;
|
|
615
|
-
/**
|
|
616
|
-
* Create a mutual-cleanup link with a resource that might be stopped or
|
|
617
|
-
* terminated in some way before the job ends. (Like a child process, a
|
|
618
|
-
* server connection, etc.)
|
|
619
|
-
*
|
|
620
|
-
* If a job uses a lot of such resources, using {@link Job.must} callbacks
|
|
621
|
-
* to trigger each one would result in an ever growing number of callbacks
|
|
622
|
-
* (and uncollectable reference to the no-longer-usable resources). So this
|
|
623
|
-
* method lets you *remove* a cleanup function when it's no longer needed:
|
|
624
|
-
* when the resource is closed or finished, invoking the callback returned
|
|
625
|
-
* by this method will remove the cleanup callback from the job, allowing
|
|
626
|
-
* the resource to be freed before the job ends, without accumulating an
|
|
627
|
-
* endless number of callbacks in the job. (Uneventful also uses this
|
|
628
|
-
* mechanism internally to link child jobs to their parents.)
|
|
629
|
-
*
|
|
630
|
-
* In order to ensure that all such "child" jobs, resources, and activities
|
|
631
|
-
* are marked as canceled *before* any side effects (such as events,
|
|
632
|
-
* callbacks or I/O operations) can occur, Uneventful prioritizes *all*
|
|
633
|
-
* release callbacks to run before *any* other callbacks of any kind. Since
|
|
634
|
-
* release callbacks are used for child jobs, this means that the entire job
|
|
635
|
-
* subtree is notified immediately of cancellation, before any other actions
|
|
636
|
-
* are taken. This ensures that no "stray" operations can continue, unaware
|
|
637
|
-
* that their job is canceled.
|
|
638
|
-
*
|
|
639
|
-
* This means, however, that release callbacks must do **only** simple
|
|
640
|
-
* actions that **can't** result in arbitrary code being synchronously run.
|
|
641
|
-
* (Some safe examples would be setting flags, cancelling event
|
|
642
|
-
* subscriptions, removing things from internal queues, etc.) Synchronously
|
|
643
|
-
* triggering events or other callbacks, however, runs the risk of that code
|
|
644
|
-
* doing things it wouldn't have done if it knew its job were canceled.
|
|
645
|
-
*
|
|
646
|
-
* Note that if you still need such actions to happen, your release callback
|
|
647
|
-
* can always add a new {@link Job.must}() or {@link Job.do}() callback at
|
|
648
|
-
* that point, and the callback will then get done during a later phase of
|
|
649
|
-
* job cleanup, without losing the benefits of the mutual-cleanup process.
|
|
650
|
-
*
|
|
651
|
-
* @param cleanup A cleanup callback. It will receive a {@link JobResult},
|
|
652
|
-
* and its return value is ignored.
|
|
653
|
-
*
|
|
654
|
-
* @returns A callback that should be used to remove the passed-in cleanup
|
|
655
|
-
* callback from the job, if the resource is disposed of before the job
|
|
656
|
-
* ends.
|
|
657
|
-
*
|
|
658
|
-
* @category Resource Tracking
|
|
659
|
-
*/
|
|
660
|
-
release(cleanup: CleanupFn<T>): DisposeFn;
|
|
661
|
-
/**
|
|
662
|
-
* Start a nested job using the given function (or {@link Yielding},
|
|
663
|
-
* promise, etc.). (Like {@link start}(), but using a specific job as the
|
|
664
|
-
* parent, rather than whatever job is active. Zero, one, and two arguments
|
|
665
|
-
* are supported, just as with start().)
|
|
666
|
-
*
|
|
667
|
-
* @category Execution Control
|
|
668
|
-
*/
|
|
669
|
-
start<T>(init?: StartFn<T> | StartObj<T>): Job<T>;
|
|
670
|
-
start<T, This>(thisArg: This, fn: StartFn<T, This>): Job<T>;
|
|
671
|
-
/**
|
|
672
|
-
* Start a nested job that will end when the given stream does
|
|
673
|
-
*
|
|
674
|
-
* This is basically shorthand for `start<void>(job => void src(sink, job,
|
|
675
|
-
* inlet))` -- i.e. a quick way to subscribe to a finite and/or pausable stream.
|
|
676
|
-
*
|
|
677
|
-
* @param src An event source or signal
|
|
678
|
-
* @param sink A callback that will receive the events or values
|
|
679
|
-
* @param inlet Optional - a {@link throttle}() to control backpressure
|
|
680
|
-
* @returns A job that can be aborted to end the subscription, and which will
|
|
681
|
-
* end naturally (with a void return or error) if the stream ends itself.
|
|
682
|
-
*
|
|
683
|
-
* @category Execution Control
|
|
684
|
-
*/
|
|
685
|
-
connect<T>(src: Stream<T>, sink: Sink<T>, inlet?: Throttle | Inlet): Connection;
|
|
686
|
-
/**
|
|
687
|
-
* Invoke a function with this job as the active one, so that calling the
|
|
688
|
-
* global {@link must} function will add cleanup callbacks to it,
|
|
689
|
-
* {@link getJob} will return it, etc. (Note: signal dependency tracking is
|
|
690
|
-
* disabled for the duration of the call.)
|
|
691
|
-
*
|
|
692
|
-
* @param fn The function to call
|
|
693
|
-
* @param args The arguments to call it with, if any
|
|
694
|
-
* @returns The result of calling fn(...args)
|
|
695
|
-
*
|
|
696
|
-
* @category Execution Control
|
|
697
|
-
*/
|
|
698
|
-
run<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F>;
|
|
699
|
-
/**
|
|
700
|
-
* Wrap a function so this job will be active when it's called.
|
|
701
|
-
*
|
|
702
|
-
* @param fn The function to wrap
|
|
703
|
-
*
|
|
704
|
-
* @returns A function with the same signature(s), but will have this job
|
|
705
|
-
* active when called.
|
|
706
|
-
*
|
|
707
|
-
* @remarks Note that if the supplied function has any custom properties,
|
|
708
|
-
* they will *not* be available on the returned function at runtime, even
|
|
709
|
-
* though TypeScript will act as if they are present at compile time. This
|
|
710
|
-
* is because the only way to copy all overloads of a function signature is
|
|
711
|
-
* to copy the exact type (as TypeScript has no way to generically say,
|
|
712
|
-
* "this is a function with all the same overloads, but none of the
|
|
713
|
-
* properties").
|
|
714
|
-
*
|
|
715
|
-
* @category Execution Control
|
|
716
|
-
*/
|
|
717
|
-
bind<F extends (...args: any[]) => any>(fn: F): F;
|
|
718
|
-
/**
|
|
719
|
-
* Release all resources held by the job.
|
|
720
|
-
*
|
|
721
|
-
* Arrange for all cleanup functions and result consumers added to the job
|
|
722
|
-
* (via release, must, do, etc.) be called in the appropriate order. When
|
|
723
|
-
* the call to end() returns, all child jobs will have been notified of
|
|
724
|
-
* their cancellation. (But not all of their cleanups or result consumers
|
|
725
|
-
* may have run yet, in the event that another job's end() is in progress
|
|
726
|
-
* when this method is called.)
|
|
727
|
-
*
|
|
728
|
-
* If any callbacks throw exceptions, they're converted to unhandled promise
|
|
729
|
-
* rejections (so that all of them will be called, even if one throws an
|
|
730
|
-
* error).
|
|
731
|
-
*
|
|
732
|
-
* Note: this method is a bound function, so you can pass it as a callback
|
|
733
|
-
* to another job, event source, etc.
|
|
734
|
-
*
|
|
735
|
-
* @category Execution Control
|
|
736
|
-
*/
|
|
737
|
-
readonly end: () => void;
|
|
738
|
-
/**
|
|
739
|
-
* Invoke a callback with the result of a job. Similar to
|
|
740
|
-
* {@link Job.must}(), except that `do` callbacks run in FIFO order after
|
|
741
|
-
* all {@link Job.must}() and {@link Job.release}() callbacks are done for
|
|
742
|
-
* the same job.
|
|
743
|
-
*
|
|
744
|
-
* These callbacks are used internally to implement promises, and should
|
|
745
|
-
* generally be used when you want to perform actions based on the *result*
|
|
746
|
-
* of a job. (Whereas {@link Job.must}() callbacks are intended to clean up
|
|
747
|
-
* resources used by the job itself, and {@link Job.release}() callbacks are
|
|
748
|
-
* used to notify other activities (such as child jobs) that they are being
|
|
749
|
-
* canceled.)
|
|
750
|
-
*
|
|
751
|
-
* @remarks The .{@link Job.onError onError}(), .{@link Job.onError onValue}(),
|
|
752
|
-
* and .{@link Job.onError onCancel}() provide shortcuts for creating `do`
|
|
753
|
-
* callbacks that only run under specific end conditions.
|
|
754
|
-
*
|
|
755
|
-
* @category Obtaining Results
|
|
756
|
-
*/
|
|
757
|
-
do(action: (res?: JobResult<T>) => unknown): this;
|
|
758
|
-
/**
|
|
759
|
-
* Invoke a callback if the job ends with an error.
|
|
760
|
-
*
|
|
761
|
-
* This is shorthand for a .{@link Job.do do}() callback that checks for an
|
|
762
|
-
* error and marks it handled, so it uses the same relative order and runs
|
|
763
|
-
* in the same group as other .do callbacks.
|
|
764
|
-
*
|
|
765
|
-
* @param cb A callback that will receive the error
|
|
766
|
-
*
|
|
767
|
-
* @category Obtaining Results
|
|
768
|
-
*/
|
|
769
|
-
onError(cb: (err: any) => unknown): this;
|
|
770
|
-
/**
|
|
771
|
-
* Invoke a callback if the job ends with a return() value.
|
|
772
|
-
*
|
|
773
|
-
* This is shorthand for a .{@link Job.do do}() callback that checks for a
|
|
774
|
-
* value result, so it uses the same relative order and runs in the same
|
|
775
|
-
* group as other .do callbacks.
|
|
776
|
-
*
|
|
777
|
-
* @param cb A callback that will receive the value
|
|
778
|
-
*
|
|
779
|
-
* @category Obtaining Results
|
|
780
|
-
*/
|
|
781
|
-
onValue(cb: (val: T) => unknown): this;
|
|
782
|
-
/**
|
|
783
|
-
* Invoke a callback if the job ends with an cancellation or
|
|
784
|
-
* .{@link Job.restart restart}().
|
|
785
|
-
*
|
|
786
|
-
* This is shorthand for a .{@link Job.do do}() callback that checks for an
|
|
787
|
-
* error and marks it handled, so it uses the same relative order and runs
|
|
788
|
-
* in the same group as other .do callbacks.
|
|
789
|
-
*
|
|
790
|
-
* @param cb A callback that will receive the error
|
|
791
|
-
*
|
|
792
|
-
* @category Obtaining Results
|
|
793
|
-
*/
|
|
794
|
-
onCancel(cb: () => unknown): this;
|
|
795
|
-
/**
|
|
796
|
-
* Restart this job - works just like .{@link Job.end end}(), except that
|
|
797
|
-
* the job isn't ended, so cleanup callbacks can be added again and won't be
|
|
798
|
-
* invoked until the next restart or the job is ended. Note that the job's
|
|
799
|
-
* startup code will *not* be rerun: this just runs an early cleanup and
|
|
800
|
-
* then "uncancels" the job, changing its {@link Job.result result}() from
|
|
801
|
-
* {@link CancelResult} back to undefined. It's up to you to do any needed
|
|
802
|
-
* re-initialization.
|
|
803
|
-
*
|
|
804
|
-
* Unlinke .{@link Job.end end}(), restart() guarantees that *all* cleanups
|
|
805
|
-
* and result consumers for the target job will have completed running when
|
|
806
|
-
* it returns.
|
|
807
|
-
*
|
|
808
|
-
* @see The {@link restarting} wrapper can be used to make a function that
|
|
809
|
-
* runs over and over in the same job, restarting each time.
|
|
810
|
-
*
|
|
811
|
-
* @category Execution Control
|
|
812
|
-
*/
|
|
813
|
-
restart(): this;
|
|
814
|
-
/**
|
|
815
|
-
* Informs a job of an unhandled error from one of its children.
|
|
816
|
-
*
|
|
817
|
-
* If the job has an .{@link Job.asyncCatch asyncCatch}() handler set, it
|
|
818
|
-
* will be called with the error, otherwise the job will end with the
|
|
819
|
-
* supplied error. If the error then isn't handled by a listener on the
|
|
820
|
-
* job, the error will cascade to an asyncThrow on the job's parent, until
|
|
821
|
-
* the {@link detached} job and its asyncCatch handler is reached. (Which
|
|
822
|
-
* defaults to creating an unhandled promise rejection.)
|
|
823
|
-
*
|
|
824
|
-
* Note: application code should not normally need to call this method
|
|
825
|
-
* directly, as it's automatically invoked on a job's parent if the job
|
|
826
|
-
* fails with no error listeners. (That is, if a job result isn't awaited
|
|
827
|
-
* by anything and has no onError handlers, and the job throws, then the
|
|
828
|
-
* error is automatically asyncThrow()n to the job's parent.)
|
|
829
|
-
*
|
|
830
|
-
* @param err The error thrown by the child job
|
|
831
|
-
*
|
|
832
|
-
* @category Handling Errors
|
|
833
|
-
*/
|
|
834
|
-
asyncThrow(err: any): this;
|
|
835
|
-
/**
|
|
836
|
-
* Set up a callback to receive unhandled errors from child jobs.
|
|
837
|
-
*
|
|
838
|
-
* Setting an async-catch handler allows you to create robust parent jobs
|
|
839
|
-
* that log or report errors and restart either a single job or an entire
|
|
840
|
-
* group of them, in the event that a child job malfunctions in a way that's
|
|
841
|
-
* not caught elsewhere.
|
|
842
|
-
*
|
|
843
|
-
* @param handler Either an error-receiving callback, or null. If null,
|
|
844
|
-
* asyncThrow()n errors for the job will be passed to the job's throw()
|
|
845
|
-
* method instead. If a callback is given, it's called with `this` bound to
|
|
846
|
-
* the relevant job instance.
|
|
847
|
-
*
|
|
848
|
-
* @category Handling Errors
|
|
849
|
-
*/
|
|
850
|
-
asyncCatch(handler: ((this: Job, err: any) => unknown) | null): this;
|
|
851
|
-
/**
|
|
852
|
-
* End the job with a thrown error, passing an {@link ErrorResult} to the
|
|
853
|
-
* cleanup callbacks. (Throws an error if the job is already ended or is
|
|
854
|
-
* currently restarting.) Provides the same execution and ordering
|
|
855
|
-
* guarantees as .{@link Job.end end}().
|
|
856
|
-
*
|
|
857
|
-
* Note: since this immediately ends the job with an error, it should only
|
|
858
|
-
* be called by the job when it is no longer able to continue. If you want
|
|
859
|
-
* to notify a job about an error in a *different* job, you may want to use
|
|
860
|
-
* .{@link Job.asyncThrow asyncThrow}() instead.
|
|
861
|
-
*
|
|
862
|
-
* @category Producing Results
|
|
863
|
-
*/
|
|
864
|
-
throw(err: any): this;
|
|
865
|
-
/**
|
|
866
|
-
* End the job with a return value, passing a {@link ValueResult} to the
|
|
867
|
-
* cleanup callbacks. (Throws an error if the job is already ended or is
|
|
868
|
-
* currently restarting.) Provides the same execution and ordering
|
|
869
|
-
* guarantees as .{@link Job.end end}().
|
|
870
|
-
*
|
|
871
|
-
* @category Producing Results
|
|
872
|
-
*/
|
|
873
|
-
return(val: T): this;
|
|
874
|
-
}
|
|
875
|
-
/**
|
|
876
|
-
* A pausable computation that ultimately produces a value of type T.
|
|
877
|
-
*
|
|
878
|
-
* An item of this type can be used to either create a job of type T, or awaited
|
|
879
|
-
* in a job via `yield *` to obtain the value.
|
|
880
|
-
*
|
|
881
|
-
* Any generator function that ultimately returns a value, implicitly returns a
|
|
882
|
-
* Yielding of that type, but it's best to *explicitly* declare this so that
|
|
883
|
-
* TypeScript can properly type check your yield expressions. (e.g. `function
|
|
884
|
-
* *(): Yielding<number> {}` for a generator function that ultimately returns a
|
|
885
|
-
* number.)
|
|
886
|
-
*
|
|
887
|
-
* Generator functions implementing this type should only ever `yield *` to
|
|
888
|
-
* things that are of Yielding type, such as a {@link Job}, {@link to}() or
|
|
889
|
-
* other generators declared Yielding.
|
|
890
|
-
*
|
|
891
|
-
* @yields {@link Suspend}\<any>
|
|
892
|
-
* @returns T
|
|
893
|
-
*
|
|
894
|
-
*
|
|
895
|
-
* @category Types and Interfaces
|
|
896
|
-
*/
|
|
897
|
-
type Yielding<T> = {
|
|
898
|
-
/**
|
|
899
|
-
* An iterator suitable for use with `yield *` (in a job generator) to
|
|
900
|
-
* obtain a result.
|
|
901
|
-
*
|
|
902
|
-
* @category Obtaining Results
|
|
903
|
-
*/
|
|
904
|
-
[Symbol.iterator](): JobIterator<T>;
|
|
905
|
-
};
|
|
906
|
-
/**
|
|
907
|
-
* An iterator yielding {@link Suspend} callbacks. (An implementation detail of
|
|
908
|
-
* the {@link Yielding} type.)
|
|
909
|
-
*
|
|
910
|
-
* @category Types and Interfaces
|
|
911
|
-
*/
|
|
912
|
-
type JobIterator<T> = Generator<Suspend<any>, T, any>;
|
|
913
|
-
/**
|
|
914
|
-
* An asynchronous operation that can be waited on by a {@link Job}.
|
|
915
|
-
*
|
|
916
|
-
* When a {@link JobIterator} yields a Suspend, the job invokes it with a
|
|
917
|
-
* {@link Request}. The Suspend function should arrange for the request to be
|
|
918
|
-
* settled (via {@link resolve} or {@link reject}).
|
|
919
|
-
*
|
|
920
|
-
* Note: If the request is not settled, **the job will be suspended until
|
|
921
|
-
* cancelled by outside forces**. (Such as its enclosing job ending, or
|
|
922
|
-
* explicit throw()/return() calls on the job instance.)
|
|
923
|
-
*
|
|
924
|
-
* Also note that any subjobs the Suspend function creates (or cleanup callbacks
|
|
925
|
-
* it registers) **will not be cleaned up until the *calling* job ends**. So
|
|
926
|
-
* any resources that won't be needed once the job is resumed should be
|
|
927
|
-
* explicitly disposed of -- in which case you should probably just `yield *` to
|
|
928
|
-
* a {@link start}(), instead of yielding a Suspend!
|
|
929
|
-
*
|
|
930
|
-
* @category Types and Interfaces
|
|
931
|
-
*/
|
|
932
|
-
type Suspend<T> = (request: Request<T>) => void;
|
|
933
|
-
/**
|
|
934
|
-
* A request for a value (or error) to be returned asynchronously.
|
|
935
|
-
*
|
|
936
|
-
* A request is like the inverse of a Promise: instead of waiting for it to
|
|
937
|
-
* settle, you settle it by passing it to {@link resolve}() or {@link reject}().
|
|
938
|
-
* Like a promise, it can only be settled once: resolving or rejecting it after
|
|
939
|
-
* it's already resolved or rejected has no effect.
|
|
940
|
-
*
|
|
941
|
-
* Settling a request will cause the requesting job (or other code) to resume
|
|
942
|
-
* immediately, running up to its next suspension or termination. (Unless it's
|
|
943
|
-
* settled while the requesting job is already on the call stack, in which case
|
|
944
|
-
* the job will be resumed later.)
|
|
945
|
-
*
|
|
946
|
-
* (Note: do not call a Request directly, unless you want your code to maybe
|
|
947
|
-
* break in future. Use resolve or reject (or {@link resolver}() or
|
|
948
|
-
* {@link rejecter}()), as 1) they'll shield you from future changes to this
|
|
949
|
-
* protocol and 2) they have better type checking anyway.)
|
|
950
|
-
*
|
|
951
|
-
* @category Types and Interfaces
|
|
952
|
-
*/
|
|
953
|
-
interface Request<T> {
|
|
954
|
-
(op: "next", val: T, err?: any): void;
|
|
955
|
-
(op: "throw", val: undefined | null, err: any): void;
|
|
956
|
-
(op: "next" | "throw", val?: T | undefined | null, err?: any): void;
|
|
957
|
-
}
|
|
958
|
-
/**
|
|
959
|
-
* A subscribable function used to trigger signal recalculations
|
|
960
|
-
*
|
|
961
|
-
* It must accept a callback, and should arrange (via {@link must}()) to
|
|
962
|
-
* unsubscribe when its calling job ends. Once subscribed, it should
|
|
963
|
-
* invoke the callback to trigger recalculation of the signal(s) that
|
|
964
|
-
* were targeted via {@link recalcWhen}.
|
|
965
|
-
*
|
|
966
|
-
* @category Types and Interfaces
|
|
967
|
-
*/
|
|
968
|
-
type RecalcSource = ((cb: () => void) => unknown);
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Is the given value a function?
|
|
972
|
-
*
|
|
973
|
-
* @category Types and Interfaces
|
|
974
|
-
*/
|
|
975
|
-
declare function isFunction(f: any): f is Function;
|
|
976
12
|
/**
|
|
977
13
|
* Return the currently-active Job, or throw an error if none is active.
|
|
978
14
|
*
|
|
@@ -988,8 +24,7 @@ declare function getJob<T = unknown>(): Job<T>;
|
|
|
988
24
|
* reasons to just use one directly. (Like when Uneventful uses this function
|
|
989
25
|
* to implement jobs' promise methods!)
|
|
990
26
|
*
|
|
991
|
-
* @param job
|
|
992
|
-
* the active job is used.
|
|
27
|
+
* @param job The job to get a native promise for.
|
|
993
28
|
*
|
|
994
29
|
* @returns A {@link Promise} that resolves or rejects according to whether the
|
|
995
30
|
* job returns or throws. If the job is canceled, the promise is rejected with
|
|
@@ -997,7 +32,7 @@ declare function getJob<T = unknown>(): Job<T>;
|
|
|
997
32
|
*
|
|
998
33
|
* @category Jobs
|
|
999
34
|
*/
|
|
1000
|
-
declare function nativePromise<T>(job
|
|
35
|
+
declare function nativePromise<T>(job: Job<T>): Promise<T>;
|
|
1001
36
|
/**
|
|
1002
37
|
* Return a new {@link Job}. If *either* a parent parameter or stop function
|
|
1003
38
|
* are given, the new job is linked to the parent.
|
|
@@ -1015,15 +50,17 @@ declare function nativePromise<T>(job?: Job<T>): Promise<T>;
|
|
|
1015
50
|
*
|
|
1016
51
|
* @category Jobs
|
|
1017
52
|
*/
|
|
1018
|
-
declare const makeJob: <T
|
|
53
|
+
declare const makeJob: <T>(parent?: Job, stop?: CleanupFn) => Job<T>;
|
|
1019
54
|
/**
|
|
1020
55
|
* A special {@link Job} with no parents, that can be used to create standalone
|
|
1021
56
|
* jobs. detached.start() returns a new detached job, detached.run() can be
|
|
1022
57
|
* used to run code that expects to create a child job, and detached.bind() can
|
|
1023
58
|
* wrap a function to work without a parent job.
|
|
1024
59
|
*
|
|
1025
|
-
* (Note that
|
|
1026
|
-
* explicitly, or
|
|
60
|
+
* (Note that such `detached` child jobs *must* exit themselves or be stopped
|
|
61
|
+
* explicitly from outside, or else they may "run" forever, never running their
|
|
62
|
+
* cleanup callbacks. Unlike other jobs, they don't end when their parent does
|
|
63
|
+
* because the `detached` job never "ends".)
|
|
1027
64
|
*
|
|
1028
65
|
* The detached job has a few special features and limitations:
|
|
1029
66
|
*
|
|
@@ -1062,596 +99,6 @@ declare function to<T>(p: Promise<T> | PromiseLike<T> | T): Yielding<T>;
|
|
|
1062
99
|
*/
|
|
1063
100
|
declare function sleep(ms: number): Yielding<void>;
|
|
1064
101
|
|
|
1065
|
-
/**
|
|
1066
|
-
* The result type returned from calls to {@link Each}.next()
|
|
1067
|
-
*
|
|
1068
|
-
* @category Types and Interfaces
|
|
1069
|
-
*/
|
|
1070
|
-
type EachResult<T> = {
|
|
1071
|
-
/** The value provided by the source being iterated */
|
|
1072
|
-
item: T;
|
|
1073
|
-
/**
|
|
1074
|
-
* A suspend callback that must be `yield`-ed before the next call to the
|
|
1075
|
-
* iterator's .next() method. (That is, you must `yield next` it exactly once
|
|
1076
|
-
* per loop pass. See {@link each}() for more details.)
|
|
1077
|
-
*/
|
|
1078
|
-
next: Suspend<void>;
|
|
1079
|
-
};
|
|
1080
|
-
/**
|
|
1081
|
-
* The iterable returned by `yield *` {@link each}()
|
|
1082
|
-
*
|
|
1083
|
-
* @category Types and Interfaces
|
|
1084
|
-
*/
|
|
1085
|
-
type Each<T> = IterableIterator<EachResult<T>>;
|
|
1086
|
-
/**
|
|
1087
|
-
* Asynchronously iterate over an event source
|
|
1088
|
-
*
|
|
1089
|
-
* Usage:
|
|
1090
|
-
*
|
|
1091
|
-
* ```ts
|
|
1092
|
-
* for (const {item: event, next} of yield *each(mouseMove)) {
|
|
1093
|
-
* console.log(event.clientX, event.clientY);
|
|
1094
|
-
* yield next; // required exactly once per iteration, even/w continue!
|
|
1095
|
-
* }
|
|
1096
|
-
* ```
|
|
1097
|
-
*
|
|
1098
|
-
* each(eventSource) yield-returns an iterator of `{item, next}` pairs. The
|
|
1099
|
-
* item is the data supplied by the event source, and `next` is a
|
|
1100
|
-
* {@link Suspend}\<void\> that advances the iterator to the next item. It
|
|
1101
|
-
* *must* be yielded exactly once per loop iteration. If you use `continue` to
|
|
1102
|
-
* shortcut the loop body, you must `yield next` *before* doing so.
|
|
1103
|
-
*
|
|
1104
|
-
* The for-loop will end if the source ends, errors, or is canceled. The source
|
|
1105
|
-
* is paused while the loop body is running, and resumed when the `yield next`
|
|
1106
|
-
* happens. If events arrive anyway (e.g. because the source doesn't support
|
|
1107
|
-
* pausing), they will be ignored unless you pipe the source through the
|
|
1108
|
-
* {@link slack}() operator to provide a buffer. If the for-loop is exited
|
|
1109
|
-
* early for any reason (or the iterator's `.return()` is called), the source is
|
|
1110
|
-
* unsubscribed and the iteration ended.
|
|
1111
|
-
*
|
|
1112
|
-
* @category Stream Consumers
|
|
1113
|
-
*/
|
|
1114
|
-
declare function each<T>(src: Stream<T>): Yielding<Each<T>>;
|
|
1115
|
-
/**
|
|
1116
|
-
* An object that can be waited on with `yield *until()`, by calling its
|
|
1117
|
-
* "uneventful.until" method. (This mostly exists to allow Signals to optimize
|
|
1118
|
-
* their until() implementation, but is also open for extensions.)
|
|
1119
|
-
*
|
|
1120
|
-
* @category Types and Interfaces
|
|
1121
|
-
*/
|
|
1122
|
-
interface UntilMethod<T> {
|
|
1123
|
-
/** Return an async op to resume once a truthy value is available */
|
|
1124
|
-
"uneventful.until"(): Yielding<T>;
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* An object that can be waited on with `yield *next()`, by calling its
|
|
1128
|
-
* "uneventful.next" method. (This mostly exists to allow Signals to optimize
|
|
1129
|
-
* their next() implementation, but is also open for extensions.)
|
|
1130
|
-
*
|
|
1131
|
-
* @category Types and Interfaces
|
|
1132
|
-
*/
|
|
1133
|
-
interface NextMethod<T> {
|
|
1134
|
-
/** Return an async op to resume with the "next" (i.e. not current) value produced */
|
|
1135
|
-
"uneventful.next"(): Yielding<T>;
|
|
1136
|
-
}
|
|
1137
|
-
/**
|
|
1138
|
-
* Wait for and return the next truthy value (or error) from a data source (when
|
|
1139
|
-
* processed with `yield *` within a {@link Job}).
|
|
1140
|
-
*
|
|
1141
|
-
* This differs from {@link next}() in that it waits for the next "truthy" value
|
|
1142
|
-
* (i.e., not null, false, zero, empty string, etc.), and when used with signals
|
|
1143
|
-
* or a signal-using function, it can resume *immediately* if the result is
|
|
1144
|
-
* already truthy. (It also supports zero-argument signal-using functions,
|
|
1145
|
-
* automatically wrapping them with {@link cached}(), as the common use case for
|
|
1146
|
-
* until() is to wait for an arbitrary condition to be satisfied.)
|
|
1147
|
-
*
|
|
1148
|
-
* @param source The source to wait on, which can be:
|
|
1149
|
-
* - An object with an `"uneventful.until"` method returning a {@link Yielding}
|
|
1150
|
-
* (in which case the result will be the the result of calling that method)
|
|
1151
|
-
* - A {@link Signal}, or a zero-argument function returning a value based on
|
|
1152
|
-
* signals (in which case the job resumes as soon as the result is truthy,
|
|
1153
|
-
* perhaps immediately)
|
|
1154
|
-
* - A {@link Source} (in which case the job resumes on the next truthy value
|
|
1155
|
-
* it produces
|
|
1156
|
-
*
|
|
1157
|
-
* (Note: if the supplied source is a function with a non-zero `.length`, it is
|
|
1158
|
-
* assumed to be a {@link Source}.)
|
|
1159
|
-
*
|
|
1160
|
-
* @returns a Yieldable that when processed with `yield *` in a job, will return
|
|
1161
|
-
* the triggered event, or signal value. An error is thrown if event stream
|
|
1162
|
-
* throws or closes early, or the signal throws.
|
|
1163
|
-
*
|
|
1164
|
-
* @category Signals
|
|
1165
|
-
* @category Scheduling
|
|
1166
|
-
*/
|
|
1167
|
-
declare function until<T>(source: UntilMethod<T> | Stream<T> | (() => T)): Yielding<T>;
|
|
1168
|
-
/**
|
|
1169
|
-
* Wait for and return the next value (or error) from a data source (when
|
|
1170
|
-
* processed with `yield *` within a {@link Job}).
|
|
1171
|
-
*
|
|
1172
|
-
* This differs from {@link until}() in that it waits for the *next* value
|
|
1173
|
-
* (truthy or not!), and it never resumes immediately for signals, but instead
|
|
1174
|
-
* waits for the signal to *change*. (Also, it does not support zero-argument
|
|
1175
|
-
* functions, unless you wrap them with {@link cached}() first.)
|
|
1176
|
-
*
|
|
1177
|
-
* @param source The source to wait on, which can be:
|
|
1178
|
-
* - An object with an `"uneventful.next"` method returning a {@link Yielding}
|
|
1179
|
-
* (in which case the result will be the the result of calling that method)
|
|
1180
|
-
* - A {@link Signal} or {@link Source} (in which case the job resumes on the
|
|
1181
|
-
* next value it produces)
|
|
1182
|
-
*
|
|
1183
|
-
* (Note: if the supplied source is a function with a non-zero `.length`, it is
|
|
1184
|
-
* assumed to be a {@link Source}.)
|
|
1185
|
-
*
|
|
1186
|
-
* @returns a Yieldable that when processed with `yield *` in a job, will return
|
|
1187
|
-
* the triggered event, or signal value. An error is thrown if event stream
|
|
1188
|
-
* throws or closes early, or the signal throws.
|
|
1189
|
-
*
|
|
1190
|
-
* @category Stream Consumers
|
|
1191
|
-
* @category Scheduling
|
|
1192
|
-
*/
|
|
1193
|
-
declare function next<T>(source: NextMethod<T> | Stream<T>): Yielding<T>;
|
|
1194
|
-
/**
|
|
1195
|
-
* Run a {@link restarting}() callback for each value produced by a source.
|
|
1196
|
-
*
|
|
1197
|
-
* With each event that occurs, any previous callback run is cleaned up before
|
|
1198
|
-
* the new one begins. (And the last run is cleaned up when the connection or
|
|
1199
|
-
* job ends.)
|
|
1200
|
-
*
|
|
1201
|
-
* This function is almost the exact opposite of {@link each}(), in that the
|
|
1202
|
-
* stream is never paused (unless you do so manually via a throttle or inlet),
|
|
1203
|
-
* and if the "loop body" (callback job) is still running when a new value
|
|
1204
|
-
* arrives, forEach() restarts the job instead of dropping the value.
|
|
1205
|
-
*
|
|
1206
|
-
* @param src An event source (i.e. a {@link Source} or {@link Signal})
|
|
1207
|
-
* @param sink A callback that receives values from the source
|
|
1208
|
-
* @param inlet An optional throttle or inlet that will be used to pause the
|
|
1209
|
-
* source (if it's a signal or supports backpressure)
|
|
1210
|
-
* @returns a {@link Connection} that can be used to detect the stream
|
|
1211
|
-
* end/error, or ended to close it early.
|
|
1212
|
-
*
|
|
1213
|
-
* @category Stream Consumers
|
|
1214
|
-
*/
|
|
1215
|
-
declare function forEach<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection;
|
|
1216
|
-
/**
|
|
1217
|
-
* When called without a source, return a callback suitable for use w/{@link pipe}().
|
|
1218
|
-
* e.g.:
|
|
1219
|
-
*
|
|
1220
|
-
* ```ts
|
|
1221
|
-
* pipe(someSource, ..., forEach(v => { doSomething(v); }), optionalInlet));
|
|
1222
|
-
* ```
|
|
1223
|
-
*
|
|
1224
|
-
*/
|
|
1225
|
-
declare function forEach<T>(sink: Sink<T>, inlet?: Inlet): (src: Stream<T>) => Connection;
|
|
1226
|
-
|
|
1227
|
-
/**
|
|
1228
|
-
* A decorator function that supports both TC39 and "legacy" decorator protocols
|
|
1229
|
-
*
|
|
1230
|
-
* @template F the type of method this decorator can decorate. If the method
|
|
1231
|
-
* doesn't conform to this type, compile-time type checks will fail.
|
|
1232
|
-
*
|
|
1233
|
-
* @category Types and Interfaces
|
|
1234
|
-
*/
|
|
1235
|
-
type GenericMethodDecorator<F extends AnyFunction> = {
|
|
1236
|
-
/** TC39 Method Decorator @hidden */
|
|
1237
|
-
(fn: F, ctx?: {
|
|
1238
|
-
kind: "method";
|
|
1239
|
-
}): F;
|
|
1240
|
-
/** Legacy Method Decorator @hidden */
|
|
1241
|
-
(proto: object, name: string | symbol, desc?: {
|
|
1242
|
-
value?: F;
|
|
1243
|
-
}): void;
|
|
1244
|
-
};
|
|
1245
|
-
/**
|
|
1246
|
-
* The interface provided by {@link rule}, and other {@link rule.factory}()
|
|
1247
|
-
* functions.
|
|
1248
|
-
*
|
|
1249
|
-
* @category Types and Interfaces
|
|
1250
|
-
*/
|
|
1251
|
-
interface RuleFactory {
|
|
1252
|
-
/**
|
|
1253
|
-
* @inheritdoc rule factory tied to a specific scheduler. See {@link rule} for
|
|
1254
|
-
* more details.
|
|
1255
|
-
*/
|
|
1256
|
-
(fn: (stop: DisposeFn) => OptionalCleanup): DisposeFn;
|
|
1257
|
-
/**
|
|
1258
|
-
* Stop the currently-executing rule, or throw an error if no rule is
|
|
1259
|
-
* currently running.
|
|
1260
|
-
*/
|
|
1261
|
-
stop(): void;
|
|
1262
|
-
/**
|
|
1263
|
-
* Observe a condition and apply an action.
|
|
1264
|
-
*
|
|
1265
|
-
* This is roughly equivalent to `rule(() => { if (condition()) return
|
|
1266
|
-
* action(); })`, except that the rule is *only* rerun if the `action`'s
|
|
1267
|
-
* dependencies change, *or* the truthiness of `condition()` changes. It
|
|
1268
|
-
* will *not* be re-run if only the dependencies of `condition()` have
|
|
1269
|
-
* changed, without affecting its truthiness.
|
|
1270
|
-
*
|
|
1271
|
-
* This behavior can be important for rules that nest other rules, have
|
|
1272
|
-
* cleanups, fire off tasks, etc., as it may be wasteful to constantly tear
|
|
1273
|
-
* them down and set them back up if the enabling condition is a calculation
|
|
1274
|
-
* with frequently-changing dependencies.
|
|
1275
|
-
*/
|
|
1276
|
-
if(condition: () => any, action: () => OptionalCleanup): DisposeFn;
|
|
1277
|
-
/**
|
|
1278
|
-
* Decorate a method to behave as a rule, e.g.
|
|
1279
|
-
*
|
|
1280
|
-
* ```ts
|
|
1281
|
-
* const animate = rule.factory(requestAnimationFrame);
|
|
1282
|
-
*
|
|
1283
|
-
* class Draggable {
|
|
1284
|
-
* @animate.method
|
|
1285
|
-
* trackPosition(handleTop: number, handleLeft: number) {
|
|
1286
|
-
* const {clientX, clientY} = lastMouseEvent();
|
|
1287
|
-
* this.element.style.top = `${clientY - handleTop}px`;
|
|
1288
|
-
* this.element.style.left = `${clientX - handleLeft}px`;
|
|
1289
|
-
* }
|
|
1290
|
-
* }
|
|
1291
|
-
*
|
|
1292
|
-
* // Start running the method in an animation frame for every change to
|
|
1293
|
-
* // lastMouseEvent, until the current job ends:
|
|
1294
|
-
* someDraggable.trackPosition(top, left);
|
|
1295
|
-
* ```
|
|
1296
|
-
*
|
|
1297
|
-
* Each time it's (explicitly) called, the decorated method will start a new
|
|
1298
|
-
* rule, which will repeatedly run the method body (with the original
|
|
1299
|
-
* arguments and `this`) whenever its dependencies change, according to the
|
|
1300
|
-
* schedule defined by the rule factory. (So e.g. `@rule.method` will
|
|
1301
|
-
* update on the microtask after a change, etc.)
|
|
1302
|
-
*
|
|
1303
|
-
* The decorated method will always return a {@link DisposeFn} to let you
|
|
1304
|
-
* explicitly stop the rule before the current job end. But if the original
|
|
1305
|
-
* method body doesn't return a dispose function of its own, TypeScript will
|
|
1306
|
-
* consider the method to return void, unless you explicitly declare its
|
|
1307
|
-
* return type to be `DisposeFn | void`.
|
|
1308
|
-
*
|
|
1309
|
-
* Also note that since rule methods can accept arbitrary parameters, they
|
|
1310
|
-
* do not receive a `stop` parameter, and must therefore use {@link
|
|
1311
|
-
* RuleFactory.stop rule.stop}() if they wish to terminate themselves.
|
|
1312
|
-
*/
|
|
1313
|
-
readonly method: GenericMethodDecorator<(...args: any[]) => OptionalCleanup>;
|
|
1314
|
-
/**
|
|
1315
|
-
* Return a rule factory for the given scheduling function, that you can
|
|
1316
|
-
* then use to make rules that run in a specific time frame.
|
|
1317
|
-
*
|
|
1318
|
-
* ```ts
|
|
1319
|
-
* // `animate` will now create rules that run during animation fames
|
|
1320
|
-
* const animate = rule.factory(requestAnimationFrame);
|
|
1321
|
-
*
|
|
1322
|
-
* animate(() => {
|
|
1323
|
-
* // ... do stuff in an animation frame when signals used here change
|
|
1324
|
-
* })
|
|
1325
|
-
* ```
|
|
1326
|
-
*
|
|
1327
|
-
* (In addition to being callable, the returned function is also a
|
|
1328
|
-
* {@link RuleFactory}, and thus has a `.method` decorator, `.if()` method,
|
|
1329
|
-
* and so on.)
|
|
1330
|
-
*
|
|
1331
|
-
* @param scheduleFn A single-argument scheduling function (such as
|
|
1332
|
-
* requestAnimationFrame, setImmediate, or queueMicrotask). The rule
|
|
1333
|
-
* scheduler will call it from time to time with a single callback. The
|
|
1334
|
-
* scheduling function should then arrange for that callback to be invoked
|
|
1335
|
-
* *once* at some future point, when it is the desired time for all pending
|
|
1336
|
-
* rules on that scheduler to run.
|
|
1337
|
-
*
|
|
1338
|
-
* @returns A {@link RuleFactory}, like {@link rule}. If called with the
|
|
1339
|
-
* same scheduling function more than once, it returns the same factory.
|
|
1340
|
-
*
|
|
1341
|
-
*/
|
|
1342
|
-
factory(scheduleFn: (cb: () => unknown) => unknown): RuleFactory;
|
|
1343
|
-
}
|
|
1344
|
-
/**
|
|
1345
|
-
* Subscribe a function to run every time certain values change.
|
|
1346
|
-
*
|
|
1347
|
-
* The function is run asynchronously, first after being created, then again
|
|
1348
|
-
* after there are changes in any of the values or cached functions it read
|
|
1349
|
-
* during its previous run.
|
|
1350
|
-
*
|
|
1351
|
-
* The created subscription is tied to the currently-active job (which may be
|
|
1352
|
-
* another rule). So when that job is ended or restarted, the rule will be
|
|
1353
|
-
* terminated automatically. You can also terminate it early by calling the
|
|
1354
|
-
* "stop" function that is both passed to the rule function and returned by
|
|
1355
|
-
* `rule()`.
|
|
1356
|
-
*
|
|
1357
|
-
* Note: this function will throw an error if called without an active job. If
|
|
1358
|
-
* you need a standalone rule, use {@link detached}.run to wrap the
|
|
1359
|
-
* call to rule.
|
|
1360
|
-
*
|
|
1361
|
-
* @param fn The function that will be run each time its dependencies change.
|
|
1362
|
-
* The function will be run in a restarted job each time, with any resources
|
|
1363
|
-
* used by the previous run being cleaned up. The function is passed a single
|
|
1364
|
-
* argument: a function that can be called to terminate the rule. The function
|
|
1365
|
-
* should return a cleanup function or void.
|
|
1366
|
-
*
|
|
1367
|
-
* @returns A function that can be called to terminate the rule.
|
|
1368
|
-
*
|
|
1369
|
-
* @category Signals
|
|
1370
|
-
*/
|
|
1371
|
-
declare const rule: ((action: (stop: DisposeFn) => OptionalCleanup) => DisposeFn) & RuleFactory;
|
|
1372
|
-
/**
|
|
1373
|
-
* Synchronously run any pending rules tied to a specific schedule.
|
|
1374
|
-
*
|
|
1375
|
-
* (Note: "pending" rules are ones with at least one changed ancestor
|
|
1376
|
-
* dependency; this doesn't mean they will actually *do* anything, since
|
|
1377
|
-
* intermediate cached() function results might end up unchanged.)
|
|
1378
|
-
*
|
|
1379
|
-
* You should normally only need to call this when you need to *force*
|
|
1380
|
-
* side-effects to occur within a specific *synchronous* timeframe, e.g. if
|
|
1381
|
-
* rules need to be able to cancel a synchronous event or continue an IndexedDB
|
|
1382
|
-
* transaction. (Otherwise, this is really only useful for testing.)
|
|
1383
|
-
*
|
|
1384
|
-
* @param scheduleFn The scheduler used to create the rule factory you wish to
|
|
1385
|
-
* run pending rules for. If not given, the default {@link rule}() factory is
|
|
1386
|
-
* targeted.
|
|
1387
|
-
*
|
|
1388
|
-
* @category Signals
|
|
1389
|
-
*/
|
|
1390
|
-
declare function runRules(scheduleFn?: (cb: () => unknown) => unknown): void;
|
|
1391
|
-
|
|
1392
|
-
/**
|
|
1393
|
-
* Error indicating a rule has attempted to write a value it indirectly
|
|
1394
|
-
* depends on, or which has already been read by another rule in the current
|
|
1395
|
-
* batch. (Also thrown when a cached function attempts to write a value at all,
|
|
1396
|
-
* directly or inidirectly.)
|
|
1397
|
-
*
|
|
1398
|
-
* @category Errors
|
|
1399
|
-
*/
|
|
1400
|
-
declare class WriteConflict extends Error {
|
|
1401
|
-
}
|
|
1402
|
-
/**
|
|
1403
|
-
* Error indicating a rule has attempted to write a value it directly depends
|
|
1404
|
-
* on, or a cached function has called itself, directly or indirectly.
|
|
1405
|
-
*
|
|
1406
|
-
* @category Errors
|
|
1407
|
-
*/
|
|
1408
|
-
declare class CircularDependency extends Error {
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1411
|
-
/**
|
|
1412
|
-
* An observable value, as a zero-argument callable with extra methods.
|
|
1413
|
-
*
|
|
1414
|
-
* In addition to being callable, signals also offer a `.value` getter, and
|
|
1415
|
-
* implement the standard JS methods `.toString()`, `.valueOf()`, and
|
|
1416
|
-
* `.toJSON()` in such a way that they reflect the signal's contents rather than
|
|
1417
|
-
* the signal itself.
|
|
1418
|
-
*
|
|
1419
|
-
* Signals also implement the {@link Source} interface, and can thus be
|
|
1420
|
-
* subscribed to. Subscribers receive the current value first, and then any
|
|
1421
|
-
* changes thereafter. They can be waited on by {@link until}(), in which case
|
|
1422
|
-
* the calling job resumes when the signal's value is truthy.
|
|
1423
|
-
*
|
|
1424
|
-
* You can also transform a signal to a {@link Writable} by calling its
|
|
1425
|
-
* .{@link Signal.withSet withSet}() method, or create a writable value using
|
|
1426
|
-
* {@link value}().
|
|
1427
|
-
*
|
|
1428
|
-
* @category Types and Interfaces
|
|
1429
|
-
*/
|
|
1430
|
-
interface Signal<T> extends SignalSource<T>, UntilMethod<T> {
|
|
1431
|
-
/**
|
|
1432
|
-
* The current value
|
|
1433
|
-
*
|
|
1434
|
-
* @category Reading
|
|
1435
|
-
*/
|
|
1436
|
-
readonly value: T;
|
|
1437
|
-
/** Current value @hidden */
|
|
1438
|
-
valueOf(): T;
|
|
1439
|
-
/** Current value as a string @hidden */
|
|
1440
|
-
toString(): string;
|
|
1441
|
-
/** The current value @hidden */
|
|
1442
|
-
toJSON(): T;
|
|
1443
|
-
/**
|
|
1444
|
-
* Get the signal's current value, without adding the signal as a dependency
|
|
1445
|
-
*
|
|
1446
|
-
* (This is exactly equivalent to calling {@link peek}(signal), and exists
|
|
1447
|
-
* here mainly for interop with other signal frameworks.)
|
|
1448
|
-
*
|
|
1449
|
-
* @category Reading */
|
|
1450
|
-
peek(): T;
|
|
1451
|
-
/** Get a read-only version of this signal @category Reading */
|
|
1452
|
-
asReadonly(): Signal<T>;
|
|
1453
|
-
/** New writable signal with a custom setter @category Writing */
|
|
1454
|
-
withSet(set: (v: T) => unknown): Writable<T>;
|
|
1455
|
-
/** @hidden */
|
|
1456
|
-
"uneventful.until"(): Yielding<T>;
|
|
1457
|
-
}
|
|
1458
|
-
/**
|
|
1459
|
-
* A {@link Signal} with a {@link Writable.set | .set()} method and writable
|
|
1460
|
-
* {@link Writable.value | .value} property.
|
|
1461
|
-
*
|
|
1462
|
-
* @category Types and Interfaces
|
|
1463
|
-
*/
|
|
1464
|
-
interface Writable<T> extends Signal<T> {
|
|
1465
|
-
/**
|
|
1466
|
-
* Set the current value. (Note: this is a bound method so it can be used
|
|
1467
|
-
* as a callback.)
|
|
1468
|
-
*
|
|
1469
|
-
* @category Writing
|
|
1470
|
-
*/
|
|
1471
|
-
readonly set: (val: T) => void;
|
|
1472
|
-
get value(): T;
|
|
1473
|
-
/** Set the current value */
|
|
1474
|
-
set value(val: T);
|
|
1475
|
-
}
|
|
1476
|
-
/**
|
|
1477
|
-
* A writable signal that can be set to either a value or an expression.
|
|
1478
|
-
*
|
|
1479
|
-
* Like a spreadsheet cell, a configurable signal can contain either a value or
|
|
1480
|
-
* a formula. If you .set() a value or change the .value property of the
|
|
1481
|
-
* signal, the formula is cleared. Conversely, if you set a formula with
|
|
1482
|
-
* .setf(), then the value is calculated using that formula from then on, until
|
|
1483
|
-
* another formula is set, or the value is changed directly again.
|
|
1484
|
-
*
|
|
1485
|
-
* @category Types and Interfaces
|
|
1486
|
-
*/
|
|
1487
|
-
interface Configurable<T> extends Writable<T> {
|
|
1488
|
-
/**
|
|
1489
|
-
* Set a formula that will be used to calculate the signal's value. If it
|
|
1490
|
-
* uses the value of other signals, this signal's value will be recalculated
|
|
1491
|
-
* when they change.
|
|
1492
|
-
*
|
|
1493
|
-
* @category Writing
|
|
1494
|
-
*/
|
|
1495
|
-
setf(expr: () => T): this;
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Create a {@link Configurable} signal with the given inital value
|
|
1499
|
-
*
|
|
1500
|
-
* @category Signals
|
|
1501
|
-
*/
|
|
1502
|
-
declare function value<T>(val?: T): Configurable<T>;
|
|
1503
|
-
/**
|
|
1504
|
-
* Create a cached version of a function. The returned callable is also a
|
|
1505
|
-
* {@link Signal}.
|
|
1506
|
-
*
|
|
1507
|
-
* Note: If the supplied function has a non-zero `.length` (i.e., it explicitly
|
|
1508
|
-
* takes arguments), it is assumed to be a {@link Source}, and the second
|
|
1509
|
-
* calling signature below will apply, even if TypeScript doesn't see it that
|
|
1510
|
-
* way!)
|
|
1511
|
-
*
|
|
1512
|
-
* @category Signals
|
|
1513
|
-
*/
|
|
1514
|
-
declare function cached<T>(compute: () => T): Signal<T>;
|
|
1515
|
-
/**
|
|
1516
|
-
* If the supplied function has a non-zero `.length` (i.e., it explicitly takes
|
|
1517
|
-
* arguments), it is assumed to be a {@link Source}, and the second argument is
|
|
1518
|
-
* a default value for the created signal to use as default value until the
|
|
1519
|
-
* source produces a value.
|
|
1520
|
-
*
|
|
1521
|
-
* The source will be subscribed *only* while the signal is subscribed as a
|
|
1522
|
-
* stream, or observed (directly or indirectly) by a rule. While subscribed,
|
|
1523
|
-
* the signal will update itself with the most recent value produced by the
|
|
1524
|
-
* source, triggering rules or events as appropriate if the value changes. When
|
|
1525
|
-
* the signal is once again unobserved (or if the source ends without an error),
|
|
1526
|
-
* its value will revert to the supplied default.
|
|
1527
|
-
*
|
|
1528
|
-
* If the source ends *with* an error, however, then the cached function will
|
|
1529
|
-
* throw that error whenever called, until/unless it becomes unobserved again.
|
|
1530
|
-
* (And thus reverts to the default value once more.)
|
|
1531
|
-
*
|
|
1532
|
-
* @param source A {@link Source} providing data which will become this signal's
|
|
1533
|
-
* value
|
|
1534
|
-
* @param defaultVal The value to use when the signal is unobserved or waiting for
|
|
1535
|
-
* the first item from the source.
|
|
1536
|
-
*/
|
|
1537
|
-
declare function cached<T>(source: Source<T>, defaultVal?: T): Signal<T>;
|
|
1538
|
-
declare function cached<T extends Signal<any>>(signal: T): T;
|
|
1539
|
-
/**
|
|
1540
|
-
* Call a function without creating a dependency on any signals it reads. (Like
|
|
1541
|
-
* {@link Signal.peek}, but for any function with any arguments.)
|
|
1542
|
-
*
|
|
1543
|
-
* You can also pass in any arguments the function takes, and the function's
|
|
1544
|
-
* return value is returned.
|
|
1545
|
-
*
|
|
1546
|
-
* (Note: Typed overloads are not supported: TypeScript will use the function's
|
|
1547
|
-
* *last* overload for argument-typing purposes. If you need to call a function
|
|
1548
|
-
* with a specific overload, wrap the function with {@link action}() instead, and
|
|
1549
|
-
* then TypeScript will be able to detect which overload you're using.)
|
|
1550
|
-
*
|
|
1551
|
-
* @returns The result of calling `fn(..args)`
|
|
1552
|
-
*
|
|
1553
|
-
* @category Signals
|
|
1554
|
-
*/
|
|
1555
|
-
declare function peek<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F>;
|
|
1556
|
-
/**
|
|
1557
|
-
* Arrange for the current signal or rule to recalculate on demand
|
|
1558
|
-
*
|
|
1559
|
-
* This lets you interop with systems that have a way to query a value and
|
|
1560
|
-
* subscribe to changes to it, but not directly produce a signal. (Such as
|
|
1561
|
-
* querying the DOM state and using a MutationObserver.)
|
|
1562
|
-
*
|
|
1563
|
-
* By calling this with a {@link Source} or {@link RecalcSource}, you arrange
|
|
1564
|
-
* for it to be subscribed, if and when the call occurs in a rule or a cached
|
|
1565
|
-
* function that's in use by a rule (directly or indirectly). When the source
|
|
1566
|
-
* emits a value, the signal machinery will invalidate the caching of the
|
|
1567
|
-
* function or rule, forcing a recalculation and subsequent rule reruns, if
|
|
1568
|
-
* applicable.
|
|
1569
|
-
*
|
|
1570
|
-
* Note: you should generally only call the 1-argument version of this function
|
|
1571
|
-
* with "static" sources - i.e. ones that won't change on every call. Otherwise,
|
|
1572
|
-
* you will end up creating new signals each time, subscribing and unsubscribing
|
|
1573
|
-
* on every call to recalcWhen().
|
|
1574
|
-
*
|
|
1575
|
-
* If the source needs to reference some object, it's best to use the 2-argument
|
|
1576
|
-
* version (i.e. `recalcWhen(someObj, factory)`, where `factory` is a function
|
|
1577
|
-
* that takes `someObj` and returns a suitable {@link RecalcSource}.)
|
|
1578
|
-
*
|
|
1579
|
-
* @remarks
|
|
1580
|
-
* recalcWhen is specifically designed so that using it does not pull in any
|
|
1581
|
-
* part of Uneventful's signals framework, in the event a program doesn't
|
|
1582
|
-
* already use it. This means you can use it in library code to provide signal
|
|
1583
|
-
* compatibility, without adding bundle bloat to code that doesn't use signals.
|
|
1584
|
-
*
|
|
1585
|
-
* @category Signals
|
|
1586
|
-
*/
|
|
1587
|
-
declare function recalcWhen(src: RecalcSource): void;
|
|
1588
|
-
/**
|
|
1589
|
-
* Two-argument variant of recalcWhen
|
|
1590
|
-
*
|
|
1591
|
-
* In certain circumstances, you may wish to use recalcWhen with a source
|
|
1592
|
-
* related to some object. You could call recalcWhen with a closure, but that
|
|
1593
|
-
* would create and discard signals on every call. So this 2-argument version
|
|
1594
|
-
* lets you avoid that by allowing the use of an arbitrary object as a key,
|
|
1595
|
-
* along with a factory function to turn the key into a {@link RecalcSource}.
|
|
1596
|
-
*
|
|
1597
|
-
* @param key an object to be used as a key
|
|
1598
|
-
*
|
|
1599
|
-
* @param factory a function that will be called with the key to obtain a
|
|
1600
|
-
* {@link RecalcSource}. (Note that this factory function must also be a static
|
|
1601
|
-
* function, not a closure, or the same memory thrash issue will occur!)
|
|
1602
|
-
*/
|
|
1603
|
-
declare function recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;
|
|
1604
|
-
/**
|
|
1605
|
-
* Wrap a function (or decorate a method) so that signals it reads are not added
|
|
1606
|
-
* as dependencies to the current rule (if any). (Basically, it's shorthand for
|
|
1607
|
-
* wrapping the function or method body in a giant call to {@link peek}().)
|
|
1608
|
-
*
|
|
1609
|
-
* So, instead of writing an action function like this:
|
|
1610
|
-
*
|
|
1611
|
-
* ```ts
|
|
1612
|
-
* function outer(arg1, arg2) {
|
|
1613
|
-
* return peek(() => {
|
|
1614
|
-
* // reactive values used here will not be added to the running rule
|
|
1615
|
-
* })
|
|
1616
|
-
* }
|
|
1617
|
-
* ```
|
|
1618
|
-
* you can just write this:
|
|
1619
|
-
* ```ts
|
|
1620
|
-
* const outer = action((arg1, arg2) => {
|
|
1621
|
-
* // reactive values used here will not be added to the running rule
|
|
1622
|
-
* });
|
|
1623
|
-
* ```
|
|
1624
|
-
* or this:
|
|
1625
|
-
* ```ts
|
|
1626
|
-
* class Something {
|
|
1627
|
-
* @action // auto-detects TC39 or legacy decorators
|
|
1628
|
-
* someMethod(arg1) {
|
|
1629
|
-
* // reactive values used here will not be added to the running rule
|
|
1630
|
-
* }
|
|
1631
|
-
* }
|
|
1632
|
-
* ```
|
|
1633
|
-
*
|
|
1634
|
-
* @param fn The function to wrap. It can take any arguments or return value,
|
|
1635
|
-
* and overloads are supported. However, any non-standard properties the
|
|
1636
|
-
* function may have had will *not* be present on the wrapped function, even if
|
|
1637
|
-
* TypeScript will act as if they are!
|
|
1638
|
-
*
|
|
1639
|
-
* @returns A wrapped version of the function that passes through its arguments
|
|
1640
|
-
* to the original function, while running with dependency tracking suppressed
|
|
1641
|
-
* (as with {@link peek}()).
|
|
1642
|
-
*
|
|
1643
|
-
* @category Signals
|
|
1644
|
-
*/
|
|
1645
|
-
declare function action<F extends AnyFunction>(fn: F): F;
|
|
1646
|
-
/** @hidden TC39 Decorator protocol */
|
|
1647
|
-
declare function action<F extends AnyFunction>(fn: F, ctx: {
|
|
1648
|
-
kind: "method";
|
|
1649
|
-
}): F;
|
|
1650
|
-
/** @hidden Legacy Decorator protocol */
|
|
1651
|
-
declare function action<F extends AnyFunction, D extends {
|
|
1652
|
-
value?: F;
|
|
1653
|
-
}>(clsOrProto: any, name: string | symbol, desc: D): D;
|
|
1654
|
-
|
|
1655
102
|
/**
|
|
1656
103
|
* A function that emits events, with a .source they're emitted from
|
|
1657
104
|
*
|
|
@@ -1720,7 +167,7 @@ declare function fromDomEvent<T extends Event>(target: EventTarget, type: string
|
|
|
1720
167
|
* Convert an iterable to a synchronous event source
|
|
1721
168
|
*
|
|
1722
169
|
* Each time the resulting source is subscribed to, it will emit an event for
|
|
1723
|
-
* each item in the iterator, then close the
|
|
170
|
+
* each item in the iterator, then close the connection. Pause/resume is
|
|
1724
171
|
* supported.
|
|
1725
172
|
*
|
|
1726
173
|
* @category Stream Producers
|
|
@@ -1730,10 +177,10 @@ declare function fromIterable<T>(iterable: Iterable<T>): Source<T>;
|
|
|
1730
177
|
* Convert a Promise to an event source
|
|
1731
178
|
*
|
|
1732
179
|
* Each time the resulting source is subscribed to, it will emit an event for
|
|
1733
|
-
* the result of the promise, then close the
|
|
1734
|
-
* rejected, in which case the
|
|
1735
|
-
* subscribed.) Non-native promises and non-promise values are converted
|
|
1736
|
-
* Promise.resolve().
|
|
180
|
+
* the result of the promise, then close the connection. (Unless the promise is
|
|
181
|
+
* rejected, in which case the connection throws and closes each time the source
|
|
182
|
+
* is subscribed.) Non-native promises and non-promise values are converted
|
|
183
|
+
* using Promise.resolve().
|
|
1737
184
|
*
|
|
1738
185
|
* @category Stream Producers
|
|
1739
186
|
*/
|
|
@@ -2020,15 +467,15 @@ declare function takeWhile<T>(condition: (v: T, idx: number) => boolean): Transf
|
|
|
2020
467
|
|
|
2021
468
|
/**
|
|
2022
469
|
* Add a cleanup function to the active job. Non-function values are ignored.
|
|
2023
|
-
* Equivalent to
|
|
2024
|
-
* {@link Job.must}() for more details.
|
|
470
|
+
* Equivalent to calling .{@link Job.must must}() on the current job. (See
|
|
471
|
+
* {@link Job.must}() for more details.)
|
|
2025
472
|
*
|
|
2026
473
|
* @category Jobs
|
|
2027
474
|
*/
|
|
2028
|
-
declare function must
|
|
475
|
+
declare function must(cleanup?: OptionalCleanup): void;
|
|
2029
476
|
/**
|
|
2030
477
|
* Start a nested job within the currently-active job. (Shorthand for
|
|
2031
|
-
*
|
|
478
|
+
* calling .{@link Job.start start}(...) on the active job.)
|
|
2032
479
|
*
|
|
2033
480
|
* This function can be called with zero, one, or two arguments:
|
|
2034
481
|
*
|
|
@@ -2141,7 +588,7 @@ declare function abortSignal(job?: Job): AbortSignal;
|
|
|
2141
588
|
* @category Jobs
|
|
2142
589
|
*/
|
|
2143
590
|
declare function restarting<F extends AnyFunction>(task: F): F;
|
|
2144
|
-
declare function restarting(): (task: () => OptionalCleanup
|
|
591
|
+
declare function restarting(): (task: () => OptionalCleanup) => void;
|
|
2145
592
|
/**
|
|
2146
593
|
* Wrap an argument-taking function so it will run in (and returns) a new Job
|
|
2147
594
|
* when called.
|
|
@@ -2206,4 +653,4 @@ declare function task<T, A extends any[], C, D extends {
|
|
|
2206
653
|
value?: (this: C, ...args: A) => StartObj<T>;
|
|
2207
654
|
}>(clsOrProto: any, name: string | symbol, desc: D): D;
|
|
2208
655
|
|
|
2209
|
-
export {
|
|
656
|
+
export { AnyFunction, Backpressure, CleanupFn, DisposeFn, type Emitter, Job, type MockSource, OptionalCleanup, Sink, Source, StartFn, StartObj, Stream, Transformer, Yielding, abortSignal, concat, concatAll, concatMap, defer, detached, emitter, empty, filter, fromAsyncIterable, fromDomEvent, fromIterable, fromPromise, fromSubscribe, fromValue, getJob, interval, isJobActive, lazy, makeJob, map, merge, mergeAll, mergeMap, mockSource, must, nativePromise, never, restarting, share, skip, skipUntil, skipWhile, slack, sleep, start, switchAll, switchMap, take, takeUntil, takeWhile, task, timeout, to };
|