@turing-machine-js/machine 6.1.0 → 6.2.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.
@@ -35,11 +35,17 @@ export default class TuringMachine {
35
35
  get tapeBlock(): TapeBlock;
36
36
  run({ initialState, stepsLimit, onStep, onPause, debug, }: RunParameter & {
37
37
  /**
38
- * Sync, ~free hook fired on every iteration. Use for logging/tracing —
39
- * the hot loop runs this without a microtask boundary, so it must not
40
- * be async.
38
+ * Hook fired on every iteration. Use for logging/tracing — and for
39
+ * yield-style coordination: returning a Promise suspends the run loop
40
+ * until it resolves, so a consumer can throttle the per-iter cadence
41
+ * (e.g. an interactive debugger awaiting a `setTimeout`-Promise between
42
+ * iters) without owning the loop. A sync `void` return adds one microtask
43
+ * boundary per iter (the engine awaits a non-Promise to keep the dispatch
44
+ * shape uniform); negligible for typical loops, but noted for tight ones.
45
+ *
46
+ * Awaited inline since v6.2.0 ([#158](https://github.com/mellonis/turing-machine-js/issues/158)).
41
47
  */
42
- onStep?: (machineState: MachineState) => void;
48
+ onStep?: (machineState: MachineState) => void | Promise<void>;
43
49
  /**
44
50
  * Async hook fired when `state.debug[when]` matches at the current
45
51
  * iteration. The promise is awaited inline, so the consumer can suspend
package/dist/index.cjs CHANGED
@@ -1070,7 +1070,7 @@ class TuringMachine {
1070
1070
  await onPause({ ...machineState, debugBreak: { before: true } });
1071
1071
  }
1072
1072
  if (onStep instanceof Function) {
1073
- onStep(machineState);
1073
+ await onStep(machineState);
1074
1074
  }
1075
1075
  if (debug && machineState.debugBreak?.after && onPause) {
1076
1076
  await onPause({ ...machineState, debugBreak: { after: true } });
package/dist/index.mjs CHANGED
@@ -1068,7 +1068,7 @@ class TuringMachine {
1068
1068
  await onPause({ ...machineState, debugBreak: { before: true } });
1069
1069
  }
1070
1070
  if (onStep instanceof Function) {
1071
- onStep(machineState);
1071
+ await onStep(machineState);
1072
1072
  }
1073
1073
  if (debug && machineState.debugBreak?.after && onPause) {
1074
1074
  await onPause({ ...machineState, debugBreak: { after: true } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turing-machine-js/machine",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "A convenient Turing machine",
5
5
  "engines": {
6
6
  "npm": ">=7.0.0"
@@ -23,6 +23,10 @@
23
23
  "turing",
24
24
  "machine"
25
25
  ],
26
+ "scripts": {
27
+ "build": "tsc --build --verbose tsconfig.build.json && node ../../scripts/build-node-entries.mjs --package=@turing-machine-js/machine",
28
+ "prepublishOnly": "npm run build"
29
+ },
26
30
  "main": "dist/index.cjs",
27
31
  "module": "dist/index.mjs",
28
32
  "types": "dist/index.d.ts",
@@ -34,5 +38,5 @@
34
38
  "default": "./dist/index.mjs"
35
39
  }
36
40
  },
37
- "gitHead": "5a3e3ced5bacd541fefdf087f5b4301267be01d2"
41
+ "gitHead": "a6a51bbf2db3d4ae692431b13956d9397df0b9e0"
38
42
  }