@kylewillett/troupe 0.2.0 → 0.3.1
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/CHANGELOG.md +16 -0
- package/README.md +8 -3
- package/dist/cell.d.ts +8 -2
- package/dist/cell.js +71 -10
- package/dist/cluster/sharding.d.ts +7 -0
- package/dist/cluster/sharding.js +14 -6
- package/dist/cluster/timed-store.d.ts +4 -0
- package/dist/cluster/timed-store.js +19 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/internal.d.ts +5 -0
- package/dist/persistence/actor.d.ts +9 -0
- package/dist/persistence/actor.js +20 -9
- package/dist/persistence/errors.d.ts +19 -0
- package/dist/persistence/errors.js +22 -0
- package/dist/persistence/index.d.ts +1 -1
- package/dist/persistence/index.js +1 -1
- package/dist/persistence/projection.d.ts +6 -0
- package/dist/persistence/projection.js +21 -5
- package/dist/rehearsal/clock.d.ts +54 -0
- package/dist/rehearsal/clock.js +203 -0
- package/dist/rehearsal/database.d.ts +116 -0
- package/dist/rehearsal/database.js +349 -0
- package/dist/rehearsal/loop.d.ts +57 -0
- package/dist/rehearsal/loop.js +153 -0
- package/dist/rehearsal/network.d.ts +120 -0
- package/dist/rehearsal/network.js +524 -0
- package/dist/rehearsal/ranges.d.ts +8 -0
- package/dist/rehearsal/ranges.js +27 -0
- package/dist/rehearsal/yield.d.ts +9 -0
- package/dist/rehearsal/yield.js +24 -0
- package/dist/system.d.ts +18 -0
- package/dist/system.js +19 -1
- package/dist/testkit/kit.d.ts +2 -1
- package/dist/testkit/kit.js +6 -2
- package/dist/timeout.d.ts +8 -0
- package/dist/timeout.js +26 -0
- package/dist/types.d.ts +31 -3
- package/package.json +1 -1
package/dist/testkit/kit.js
CHANGED
|
@@ -35,9 +35,12 @@ export function createTestKit(opts = {}) {
|
|
|
35
35
|
const probeNames = new Set();
|
|
36
36
|
let generated = 0;
|
|
37
37
|
const settle = async () => {
|
|
38
|
+
let yielded = false;
|
|
38
39
|
for (let ticks = 0;; ticks++) {
|
|
39
|
-
scheduler.runReady();
|
|
40
|
-
|
|
40
|
+
const ran = scheduler.runReady();
|
|
41
|
+
// A pipe with a signal ends when its signal aborts, so settle doesn't wait for it. It gets
|
|
42
|
+
// one event-loop turn, so a promise that has already settled still arrives (decision 0038).
|
|
43
|
+
if (handle.busy() === 0 && (handle.boundedPipes() === 0 || (yielded && ran === 0)))
|
|
41
44
|
return;
|
|
42
45
|
if (ticks >= MAX_TICKS) {
|
|
43
46
|
// An ask only time can complete is the likeliest culprit when one is pending.
|
|
@@ -50,6 +53,7 @@ export function createTestKit(opts = {}) {
|
|
|
50
53
|
// Async receive runs on real promises, so let one real event-loop turn pass. This is the
|
|
51
54
|
// one place the testkit uses real time (decision 0003).
|
|
52
55
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
56
|
+
yielded = true;
|
|
53
57
|
}
|
|
54
58
|
};
|
|
55
59
|
return {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Schedules `task` after `delayMs`, and returns a function that cancels it. */
|
|
2
|
+
export type SetTimer = (task: () => void, delayMs: number) => () => void;
|
|
3
|
+
/**
|
|
4
|
+
* Settles as `call` does, or rejects with `timedOut()` once `ms` have passed on `setTimer`,
|
|
5
|
+
* whichever comes first. An answer that comes after the timeout is dropped: the outcome stays
|
|
6
|
+
* unknown to the caller, which settles it by recovery, never by a late reply.
|
|
7
|
+
*/
|
|
8
|
+
export declare function withTimeout<T>(call: PromiseLike<T>, ms: number, setTimer: SetTimer, timedOut: () => Error): Promise<T>;
|
package/dist/timeout.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Timeouts on calls the framework makes to a store (decision 0036). A call that never settles
|
|
2
|
+
// would hold its caller for good: a persistent actor's mailbox, a projection's poll, a shard's
|
|
3
|
+
// handoff. The timer runs on the caller's scheduler (decision 0003), so virtual time reaches it.
|
|
4
|
+
// Never exported.
|
|
5
|
+
/**
|
|
6
|
+
* Settles as `call` does, or rejects with `timedOut()` once `ms` have passed on `setTimer`,
|
|
7
|
+
* whichever comes first. An answer that comes after the timeout is dropped: the outcome stays
|
|
8
|
+
* unknown to the caller, which settles it by recovery, never by a late reply.
|
|
9
|
+
*/
|
|
10
|
+
export function withTimeout(call, ms, setTimer, timedOut) {
|
|
11
|
+
// A promise settles once, so whichever comes second, the answer or the timeout, does nothing.
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const cancel = setTimer(() => {
|
|
14
|
+
reject(timedOut());
|
|
15
|
+
}, ms);
|
|
16
|
+
Promise.resolve(call).then((value) => {
|
|
17
|
+
cancel();
|
|
18
|
+
resolve(value);
|
|
19
|
+
}, (error) => {
|
|
20
|
+
cancel();
|
|
21
|
+
// The call's own reason, passed on as it came, whatever it is.
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
23
|
+
reject(error);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,31 @@ export type Result<T> = {
|
|
|
56
56
|
readonly ok: false;
|
|
57
57
|
readonly error: unknown;
|
|
58
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* What `pipeToSelf` needs from an `AbortSignal`, so the core needs no DOM or Node types. Every
|
|
61
|
+
* runtime's `AbortSignal` fits it (decision 0038).
|
|
62
|
+
*/
|
|
63
|
+
export interface PipeSignal {
|
|
64
|
+
/** Whether it has aborted already. */
|
|
65
|
+
readonly aborted: boolean;
|
|
66
|
+
/** Why it aborted: what the pipe delivers as its error. */
|
|
67
|
+
readonly reason: unknown;
|
|
68
|
+
/** Adds the listener the pipe waits on. */
|
|
69
|
+
addEventListener(type: 'abort', listener: () => void): void;
|
|
70
|
+
/** Removes it, once the promise has settled first. */
|
|
71
|
+
removeEventListener(type: 'abort', listener: () => void): void;
|
|
72
|
+
}
|
|
73
|
+
/** Options for `pipeToSelf`. */
|
|
74
|
+
export interface PipeOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Ends the pipe when it aborts: the actor gets `map({ ok: false, error: signal.reason })` at
|
|
77
|
+
* once, without waiting for the promise, and whatever the promise does later is ignored. A pipe
|
|
78
|
+
* with a signal doesn't count as busy for the testkit's `settle`, so `advance` lets time pass
|
|
79
|
+
* while it's pending. Abort it from one of the actor's timers or from its `postStop`, so
|
|
80
|
+
* something on the scheduler always ends it (decision 0038).
|
|
81
|
+
*/
|
|
82
|
+
readonly signal?: PipeSignal | undefined;
|
|
83
|
+
}
|
|
59
84
|
/**
|
|
60
85
|
* Keyed timers that send the actor a message. They belong to one incarnation: every timer is
|
|
61
86
|
* cancelled when the actor stops or restarts, and a stale context's timer methods do nothing.
|
|
@@ -135,10 +160,13 @@ export interface ActorContext<M> {
|
|
|
135
160
|
* Waits for `promise` without holding the mailbox, then sends the actor `map(result)`. `map`
|
|
136
161
|
* runs inside the actor when that message is taken, so a mapper that throws is a failure for
|
|
137
162
|
* supervision. If the actor has stopped by then, the raw `Result` becomes a dead letter. Unlike
|
|
138
|
-
* timers, a result still arrives after a restart, as a `self.tell` would.
|
|
139
|
-
*
|
|
163
|
+
* timers, a result still arrives after a restart, as a `self.tell` would. With `opts.signal`,
|
|
164
|
+
* the signal aborting ends the pipe early, and the pipe isn't busy work for `settle`
|
|
165
|
+
* ({@link PipeOptions}).
|
|
166
|
+
* @throws TypeError if `map` isn't a function, or `opts` has an unknown key or a `signal` that
|
|
167
|
+
* isn't an abort signal.
|
|
140
168
|
*/
|
|
141
|
-
pipeToSelf<T>(promise: PromiseLike<T>, map: (result: Result<T>) => M): void;
|
|
169
|
+
pipeToSelf<T>(promise: PromiseLike<T>, map: (result: Result<T>) => M, opts?: PipeOptions): void;
|
|
142
170
|
}
|
|
143
171
|
/** A lifecycle event, delivered to `onSignal`. */
|
|
144
172
|
export type Signal =
|
package/package.json
CHANGED