@omegup/msync 0.0.36 → 0.0.37

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.
Files changed (3) hide show
  1. package/index.esm.js +10 -5
  2. package/index.js +10 -5
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -947,18 +947,23 @@ class Machine {
947
947
  }
948
948
  start(cb) {
949
949
  const run = this.runner();
950
- return runCont(run(), cb);
950
+ return runCont(run, cb);
951
951
  }
952
952
  }
953
953
  const wrap = (root) => root;
954
- const runCont = async ({ next, clear }, cb) => {
955
- const { cont, info } = await next;
954
+ const runCont = async (it, cb) => {
955
+ const { next, stop, clear } = it();
956
+ const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
957
+ if (!res.ok) {
958
+ return runCont(stop, cb);
959
+ }
960
+ const { cont, info } = res.next;
956
961
  const stopped = cb?.(info);
957
962
  if (stopped) {
958
963
  await clear();
959
964
  throw new Error('Machine stopped');
960
965
  }
961
- return runCont(cont(), cb);
966
+ return runCont(cont, cb);
962
967
  };
963
968
 
964
969
  const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
@@ -1152,7 +1157,7 @@ const aggregate = (input, snapshot = true, start = Date.now()) => input(({ coll,
1152
1157
  log('execed', req, result, 'took', Date.now() - start);
1153
1158
  return result;
1154
1159
  }, err => {
1155
- log('err', req);
1160
+ log('err', req, err);
1156
1161
  throw new Error(err);
1157
1162
  });
1158
1163
  });
package/index.js CHANGED
@@ -949,18 +949,23 @@ class Machine {
949
949
  }
950
950
  start(cb) {
951
951
  const run = this.runner();
952
- return runCont(run(), cb);
952
+ return runCont(run, cb);
953
953
  }
954
954
  }
955
955
  const wrap = (root) => root;
956
- const runCont = async ({ next, clear }, cb) => {
957
- const { cont, info } = await next;
956
+ const runCont = async (it, cb) => {
957
+ const { next, stop, clear } = it();
958
+ const res = await next.then(next => ({ ok: true, next }), err => ({ ok: false, err }));
959
+ if (!res.ok) {
960
+ return runCont(stop, cb);
961
+ }
962
+ const { cont, info } = res.next;
958
963
  const stopped = cb?.(info);
959
964
  if (stopped) {
960
965
  await clear();
961
966
  throw new Error('Machine stopped');
962
967
  }
963
- return runCont(cont(), cb);
968
+ return runCont(cont, cb);
964
969
  };
965
970
 
966
971
  const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
@@ -1154,7 +1159,7 @@ const aggregate = (input, snapshot = true, start = Date.now()) => input(({ coll,
1154
1159
  log('execed', req, result, 'took', Date.now() - start);
1155
1160
  return result;
1156
1161
  }, err => {
1157
- log('err', req);
1162
+ log('err', req, err);
1158
1163
  throw new Error(err);
1159
1164
  });
1160
1165
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.esm.js",
4
4
  "typings": "index.d.ts",
5
5
  "name": "@omegup/msync",
6
- "version": "0.0.36",
6
+ "version": "0.0.37",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",