-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.mjs
45 lines (37 loc) · 860 Bytes
/
example.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { create, memo } from './asyncforge.js'
const a = memo()
const b = memo()
const store = create()
store.run(() => {
a.set(42)
b.set(123)
// simulate an event loop turn
setImmediate(() => {
console.log('-- first event loop turn --')
console.log('a', a())
console.log('b', b())
})
})
create(() => {
a.set(43)
b.set(321)
// simulate an event loop turn
setImmediate(() => {
console.log('-- second event loop turn --')
console.log('a', a())
console.log('b', b())
store.run(() => {
setImmediate(() => {
console.log('-- third event loop turn --')
console.log('a', a())
console.log('b', b())
})
})
setImmediate(() => {
store.enterWith()
console.log('-- fourth event loop turn --')
console.log('a', a())
console.log('b', b())
})
})
})