Skip to content

Instantly share code, notes, and snippets.

@domosedov
Last active May 22, 2022 20:21
Show Gist options
  • Save domosedov/c3fc9964ecb55a6fa93cbbad859346fc to your computer and use it in GitHub Desktop.
Save domosedov/c3fc9964ecb55a6fa93cbbad859346fc to your computer and use it in GitHub Desktop.
Await scope all calculations
const start = createEvent()
const waitFx = createEffect(ms => {
return new Promise(r => setTimeout(r, ms))
})
const $ = createStore(null)
sample({
clock: start,
fn: () => 3_000,
target: waitFx,
})
$.on(waitFx.done, () => 'some data')
const trackScope = scope => {
const track = createEvent()
return allSettled(track, {scope})
}
const scope = fork()
const test = scopeBind(start, {scope})
patronum.debug(waitFx)
test()
await trackScope(scope)
const s = scope.getState($)
console.log("scope done", s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment