Last active
May 22, 2022 20:21
-
-
Save domosedov/c3fc9964ecb55a6fa93cbbad859346fc to your computer and use it in GitHub Desktop.
Await scope all calculations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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