@astrale-os/kernel-client 1.0.0-beta.8 → 1.0.0-beta.9

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.
@@ -13,6 +13,11 @@ const READ_ATTEMPTS = 8;
13
13
  const LAPSED_WAIT_MS = 1_000;
14
14
  /** No wait is sent again with less time left than this. */
15
15
  const MINIMUM_WAIT_MS = 1_000;
16
+ /**
17
+ * The time a wait leaves its answer to come back. The Kernel bounds a wait by its own request
18
+ * deadline, never by this call's: the client ends each wait this long before its request times out.
19
+ */
20
+ const ANSWER_MARGIN_MS = 2_000;
16
21
  /** Bind the `K.Execution` Methods to one call capability. */
17
22
  export function createExecution(call) {
18
23
  // A completed value is the handler output, which only the reference types.
@@ -64,18 +69,21 @@ export function executionMethods(call, accept) {
64
69
  return read(deadlineOf(options), options, async (attempt) => statusOf(id, await send(id, methods.status, {}, attempt)));
65
70
  },
66
71
  /**
67
- * Each request waits for the time left, which the Kernel bounds by its own request deadline. A
68
- * wait that lapsed after waiting is sent again while time is left; any other end of the wait is
69
- * the caller's.
72
+ * Each request waits for the time left, ending early enough for its answer to come back before
73
+ * the call's deadline, and lives as long as its wait and that answer. A wait that lapsed after
74
+ * waiting is sent again while time is left; any other end of the wait is the caller's.
70
75
  */
71
76
  async result(target, wait, options) {
72
77
  const id = idOf(target);
73
78
  const deadline = deadlineOf(options);
74
- const end = Math.min(Date.now() + acceptWait(wait), deadline);
79
+ const end = Math.min(Date.now() + acceptWait(wait), deadline - ANSWER_MARGIN_MS);
75
80
  for (;;) {
76
81
  const sent = Date.now();
77
82
  try {
78
- return await read(deadline, options, async (attempt) => outcomeOf(await send(id, methods.result, { waitMs: Math.max(0, end - Date.now()) }, attempt)));
83
+ return await read(deadline, options, async (attempt) => {
84
+ const waitMs = Math.max(0, end - Date.now());
85
+ return outcomeOf(await send(id, methods.result, { waitMs }, waitRequest(waitMs, attempt)));
86
+ });
79
87
  }
80
88
  catch (error) {
81
89
  const lapsed = isPending(error) && Date.now() - sent >= LAPSED_WAIT_MS;
@@ -102,6 +110,14 @@ export function executionMethods(call, accept) {
102
110
  },
103
111
  });
104
112
  }
113
+ /**
114
+ * The request of one wait: it lives as long as the wait and the time its answer takes to come
115
+ * back, which a wait ending that long before the call's deadline keeps within it. A request that
116
+ * does not wait keeps the call's options.
117
+ */
118
+ function waitRequest(waitMs, options) {
119
+ return waitMs === 0 ? options : { ...options, timeoutMs: waitMs + ANSWER_MARGIN_MS };
120
+ }
105
121
  /** The wait an `ExecutionWait` asks for, in milliseconds. */
106
122
  export function acceptWait(wait) {
107
123
  const waitMs = wait?.waitMs ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrale-os/kernel-client",
3
- "version": "1.0.0-beta.8",
3
+ "version": "1.0.0-beta.9",
4
4
  "description": "Universal Client — protocol-first, transport-agnostic",
5
5
  "keywords": [
6
6
  "astrale",