-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temporal kills #169
Temporal kills #169
Changes from 9 commits
aa162d2
37a9af9
1c41cee
f2d414b
24d2568
206f3b9
bccb409
127fd21
e03b941
38fa57a
3601775
a99e896
0d7c02c
0dcd3cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,12 @@ var Aff = function () { | |
var FIBER = "Fiber"; // Actual fiber reference | ||
var THUNK = "Thunk"; // Primed effect, ready to invoke | ||
|
||
// Error used for early cancelation on Alt branches. | ||
// This is initialized here (rather than in the Fiber constructor) because | ||
// otherwise, in V8, this Error object indefinitely hangs on to memory that | ||
// otherwise would be garbage collected. | ||
var early = new Error("[ParAff] Early exit"); | ||
|
||
function Aff(tag, _1, _2, _3) { | ||
this.tag = tag; | ||
this._1 = _1; | ||
|
@@ -320,24 +326,41 @@ var Aff = function () { | |
|
||
case ASYNC: | ||
status = PENDING; | ||
step = runAsync(util.left, step._1, function (result) { | ||
return function () { | ||
if (runTick !== localRunTick) { | ||
return; | ||
} | ||
runTick++; | ||
Scheduler.enqueue(function () { | ||
// It's possible to interrupt the fiber between enqueuing and | ||
// resuming, so we need to check that the runTick is still | ||
// valid. | ||
if (runTick !== localRunTick + 1) { | ||
tmp = step._1; | ||
step = nonCanceler; | ||
Scheduler.enqueue(function () { | ||
if (runTick !== localRunTick) { | ||
return; | ||
} | ||
var issync = true; | ||
var resolved = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think two separate pieces of state are necessary for this check. This pattern is done in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Just so you know, I am doing this so that |
||
var canceler = runAsync(util.left, tmp, function (result) { | ||
return function () { | ||
if (runTick !== localRunTick) { | ||
return; | ||
} | ||
++runTick; | ||
resolved = true; | ||
status = STEP_RESULT; | ||
step = result; | ||
run(runTick); | ||
}); | ||
}; | ||
step = result; | ||
// Do not recurse on run if we are synchronous with runAsync. | ||
if (!issync) { | ||
run(runTick); | ||
} | ||
}; | ||
}); | ||
issync = false; | ||
// Only update the canceler if the asynchronous action has not | ||
// resolved synchronously. If it has, then the next status and | ||
// step have already been set. | ||
if (!resolved) { | ||
step = canceler; | ||
} | ||
// If runAsync already resolved then the next step needs to be | ||
// run. | ||
else { | ||
run(runTick); | ||
} | ||
}); | ||
return; | ||
|
||
|
@@ -643,9 +666,6 @@ var Aff = function () { | |
var killId = 0; | ||
var kills = {}; | ||
|
||
// Error used for early cancelation on Alt branches. | ||
var early = new Error("[ParAff] Early exit"); | ||
|
||
// Error used to kill the entire tree. | ||
var interrupt = null; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. Any thoughts as to why this happens? Just curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess it has something to do with stack frames and traces or whatever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<symbol> in Error
is what is hanging onto the memory, whatever that is, and I do not know whyError
is being referenced from the root. I figure it is some special debugging sauce in V8 being quirky.