@kylewillett/troupe 0.2.0 → 0.3.0

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.
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kylewillett/troupe",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Typed actors for TypeScript: supervision, event-sourced persistent actors, and cluster sharding.",
5
5
  "license": "MIT",
6
6
  "author": "Kyle Willett",