@awebai/oats-pi 0.70.2 → 0.70.4
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/extension/waiting-claim.mjs +25 -6
- package/package.json +1 -1
|
@@ -147,6 +147,8 @@ export function waitingClaim(pi, home) {
|
|
|
147
147
|
/** Whether a mark's holder is alive: another process that is (holderAlive), or a bridge of this
|
|
148
148
|
* process whose session has not ended. */
|
|
149
149
|
const alive = (mark) => mark.pid === self.pid && mark.start === self.start ? LIVE_BRIDGES.has(mark.token) : holderAlive(mark);
|
|
150
|
+
/** Whether two reads of the mark are one holder's one mark. */
|
|
151
|
+
const sameMark = (a, b) => a !== null && b !== null && a.pid === b.pid && a.start === b.start && a.token === b.token && a.reason === b.reason;
|
|
150
152
|
LIVE_BRIDGES.add(self.token);
|
|
151
153
|
let question;
|
|
152
154
|
let failure;
|
|
@@ -182,14 +184,27 @@ export function waitingClaim(pi, home) {
|
|
|
182
184
|
} catch { drop(draft); }
|
|
183
185
|
};
|
|
184
186
|
const removeMark = () => drop(markPath(home));
|
|
185
|
-
/** Clear the claim, then remove the mark, unless
|
|
187
|
+
/** Clear the claim, then remove the mark, unless another holder wrote its own meanwhile. False when
|
|
186
188
|
* the kernel did not take the clear: the claim may stand, so the mark stays, for a later try by
|
|
187
|
-
* this bridge or, once this pi is gone, by the home's next one.
|
|
189
|
+
* this bridge or, once this pi is gone, by the home's next one. True once the kernel took one:
|
|
190
|
+
* what this call was asked to clear is gone, even where a further clear, below, was not taken.
|
|
191
|
+
*
|
|
192
|
+
* The mark is read before the clear and again after it, and only the mark the clear answered is
|
|
193
|
+
* removed. One that another pi wrote while the clear was under way stands for a claim the clear
|
|
194
|
+
* may not have reached: removed, a question whose pi then died would stand with no mark, and no
|
|
195
|
+
* later step would find it. So a live holder's stays, with its claim; a question whose holder is
|
|
196
|
+
* already gone is cleared in turn, here, since a quiet session has no next step to do it (a clear
|
|
197
|
+
* of it the kernel does not take leaves it with its mark, for this bridge's next look); and a
|
|
198
|
+
* failed turn whose holder is gone keeps its mark, for a bridge's first run, as one left at any
|
|
199
|
+
* other moment does. */
|
|
188
200
|
const clearClaim = async () => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
for (let answered = readMark(home), taken = false; ; taken = true) {
|
|
202
|
+
if (!(await waiting("clear"))) return taken;
|
|
203
|
+
const left = readMark(home);
|
|
204
|
+
if (left === null || mine(left) || (sameMark(left, answered) && !alive(left))) { removeMark(); return true; }
|
|
205
|
+
if (alive(left) || left.reason !== "question") return true;
|
|
206
|
+
answered = left;
|
|
207
|
+
}
|
|
193
208
|
};
|
|
194
209
|
/** One step after the others. A step that throws is dropped: reporting must never break a session. */
|
|
195
210
|
const then = (run) => { steps = steps.then(run).catch(() => undefined); };
|
|
@@ -270,5 +285,9 @@ export function waitingClaim(pi, home) {
|
|
|
270
285
|
return {
|
|
271
286
|
asked(message) { question = message; change(); },
|
|
272
287
|
turnFailed(message) { ran = true; failure = message; change(); },
|
|
288
|
+
/** Resolves once every step taken so far has run, its kernel call answered: what the claim and
|
|
289
|
+
* the mark then say is this bridge's last word until its next event, or its next look by itself
|
|
290
|
+
* (lookAgain). For a caller that has to wait for the claim's state, a test above all. */
|
|
291
|
+
settled() { return steps; },
|
|
273
292
|
};
|
|
274
293
|
}
|
package/package.json
CHANGED