-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstack-safety.js
36 lines (27 loc) · 1.05 KB
/
stack-safety.js
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
// @flow
import { type ConsoleHandler, HandleConsole, HandleTime, resumeNowVoid, time, withHandler, log, run_ } from '../packages/core'
// TODO: Convert this example into a test case
// This example shows that *synchronous* effects, like console log
// run in constant stack space. If they naively used the same
// callback path as async effects, they would blow the stack.
// ConsoleHandler that doesn't actually log, since all we
// care about is proving that we're not adding stack frames
const FakeConsole: ConsoleHandler = {
'forgefx/core/console/log': args => resumeNowVoid
}
// Run a large enough number of synchronous effects, that
// we'd blow up if this was all continuation based.
function * test () {
let i = 0
while (i < 200000) {
yield * log(i++)
}
}
function * main() {
const start = yield * time()
// Run test with FakeConsole so it doesn't actually print anything
yield * withHandler(FakeConsole, test())
const end = yield * time()
yield * log(`DONE ${end - start}`)
}
run_(withHandler({ ...HandleConsole, ...HandleTime }, main()))