@omegup/msync 0.0.35 → 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 +11 -7
  2. package/index.js +11 -7
  3. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -947,19 +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 }, 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
- const it = cont();
958
962
  if (stopped) {
959
- await it.clear();
963
+ await clear();
960
964
  throw new Error('Machine stopped');
961
965
  }
962
- return runCont(it, cb);
966
+ return runCont(cont, cb);
963
967
  };
964
968
 
965
969
  const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
@@ -1153,7 +1157,7 @@ const aggregate = (input, snapshot = true, start = Date.now()) => input(({ coll,
1153
1157
  log('execed', req, result, 'took', Date.now() - start);
1154
1158
  return result;
1155
1159
  }, err => {
1156
- log('err', req);
1160
+ log('err', req, err);
1157
1161
  throw new Error(err);
1158
1162
  });
1159
1163
  });
package/index.js CHANGED
@@ -949,19 +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 }, 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
- const it = cont();
960
964
  if (stopped) {
961
- await it.clear();
965
+ await clear();
962
966
  throw new Error('Machine stopped');
963
967
  }
964
- return runCont(it, cb);
968
+ return runCont(cont, cb);
965
969
  };
966
970
 
967
971
  const merge = ({ lsource: L, rsource: R, }) => mergeIterators({ sources: { L, R } });
@@ -1155,7 +1159,7 @@ const aggregate = (input, snapshot = true, start = Date.now()) => input(({ coll,
1155
1159
  log('execed', req, result, 'took', Date.now() - start);
1156
1160
  return result;
1157
1161
  }, err => {
1158
- log('err', req);
1162
+ log('err', req, err);
1159
1163
  throw new Error(err);
1160
1164
  });
1161
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.35",
6
+ "version": "0.0.37",
7
7
  "dependencies": {
8
8
  "dayjs": "^1.11.9",
9
9
  "dotenv": "^16.3.1",