@jsenv/navi 0.29.231 → 0.29.232

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.
@@ -2902,6 +2902,9 @@ ${lines.join("\n")}`,
2902
2902
  const willPrerunSet = new Set();
2903
2903
  const willRunSet = new Set();
2904
2904
  const willPromoteSet = new Set(); // prerun -> run requested
2905
+ // Asked for, already under way: the request adds no work, and answers with
2906
+ // the run that is already carrying it (see join_active_runs below).
2907
+ const willJoinSet = new Set();
2905
2908
  const staysRunningSet = new Set();
2906
2909
  const staysAbortedSet = new Set();
2907
2910
  const staysFailedSet = new Set();
@@ -2953,8 +2956,11 @@ ${lines.join("\n")}`,
2953
2956
  } else {
2954
2957
  willRunSet.add(action);
2955
2958
  }
2959
+ } else {
2960
+ // The request performs nothing, and still has to be answered: what
2961
+ // the caller asked for is the answer, not the running.
2962
+ willJoinSet.add(action);
2956
2963
  }
2957
- // Otherwise, ignore the request (action stays as-is)
2958
2964
  } else if (isPrerun) {
2959
2965
  willPrerunSet.add(action);
2960
2966
  } else {
@@ -2981,6 +2987,7 @@ ${lines.join("\n")}`,
2981
2987
  // Special case: action was prerun but not yet requested to run
2982
2988
  // Just promote it to "run requested" without rerunning
2983
2989
  willPromoteSet.add(actionToRun);
2990
+ willJoinSet.add(actionToRun);
2984
2991
  continue;
2985
2992
  }
2986
2993
  handleActionRequest(actionToRun, "run");
@@ -3134,6 +3141,27 @@ ${lines.join("\n")}`);
3134
3141
  actionToPromote.isPrerunSignal.value = false;
3135
3142
  }
3136
3143
  }
3144
+
3145
+ // A run asked for an action that is already running, or that already holds
3146
+ // the answer, performs nothing — and answers all the same, with the run
3147
+ // that IS carrying it. `await action.run()` then means the same thing to
3148
+ // every caller: the second one waits for the first one's request and reads
3149
+ // the same data, instead of being handed `undefined` before the network has
3150
+ // said anything. See the run() JSDoc.
3151
+ {
3152
+ for (const actionToJoin of willJoinSet) {
3153
+ const runningPromise = actionPromiseMap.get(actionToJoin);
3154
+ if (runningPromise) {
3155
+ hasAsync = true;
3156
+ resultArray.push({ type: "async", promise: runningPromise });
3157
+ } else {
3158
+ resultArray.push({
3159
+ type: "sync",
3160
+ result: actionToJoin.dataSignal.peek(),
3161
+ });
3162
+ }
3163
+ }
3164
+ }
3137
3165
  if (DEBUG$2) {
3138
3166
  console.groupEnd();
3139
3167
  }
@@ -3288,10 +3316,15 @@ const createAction = (callback, rootOptions = {}) => {
3288
3316
  return dispatchSingleAction(action, "prerun", options);
3289
3317
  };
3290
3318
  /**
3291
- * Requests the action's data. An action that is already RUNNING or
3292
- * COMPLETED already has it, so the request is a no-op there: use `rerun()`
3293
- * to force a fresh run ("refresh", "check now", any explicit user intent to
3294
- * go back to the network).
3319
+ * Requests the action's data, and resolves with it.
3320
+ *
3321
+ * An action that is already RUNNING or COMPLETED already has it, so the
3322
+ * request starts nothing — it JOINS: the caller waits for the run that is
3323
+ * already carrying the question and reads the same answer. Which is what
3324
+ * makes `await action.run()` say one thing to every caller, whether it is
3325
+ * the one that asked first or the one that arrived while the request was
3326
+ * out. Use `rerun()` to force a fresh run ("refresh", "check now", any
3327
+ * explicit user intent to go back to the network).
3295
3328
  */
3296
3329
  const run = (options) => {
3297
3330
  action.debug(`${action}.run(${stringifyForDisplay(options)})`);