How to use the @effectful/es-persist-serialization.abort function in @effectful/es-persist-serialization

To help you get started, we’ve selected a few @effectful/es-persist-serialization examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github awto / effectfuljs / samples / persist-counters / state.js View on Github external
export async function load(from, param) {
  if (!from) return;
  const state = R.read(from.resume);
  R.context().running = state.running;
  state.resume.resume(param);
  await R.abort;
}
github awto / effectfuljs / samples / persist-boxes / state.js View on Github external
export async function* saveLocal(input) {
  if (!(await R.managed)) {
    yield* input;
    return;
  }
  try {
    const init = localStorage.getItem("boxes");
    if (init) {
      const state = R.read(JSON.parse(init));
      R.context().running = state.running;
      state.resume.resume();
      await R.abort;
    }
  } catch (e) {}
  for await (const i of addFlush(input)) {
    yield i;
    if (i.type === "DELETE" || i.type === "DONE") {
      let frame;
      const resume = await R.idle;
      if (resume && resume.resume) {
        frame = R.write({ running: R.context().running, resume });
        localStorage.setItem("boxes", JSON.stringify(frame));
      }
    }
  }
}