Skip to content
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

Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/Effect/Aff.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,24 +320,32 @@ 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.
var asyncAction = step._1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tmp register is for stuff like this. I'd prefer to not introduce a var in the middle of a switch.

step = nonCanceler;
Scheduler.enqueue(function () {
if (runTick !== localRunTick) {
return;
}
++runTick;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this ++runTick is necessary. There's no reentry issue here because we aren't dealing with a user-invoked callback yet.

var resolved = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 sequential code several times.
https://github.com/slamdata/purescript-aff/blob/202a3eac12a207b6f109c9708f3efb034791bd36/src/Effect/Aff.js#L776-L795

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Just so you know, I am doing this so that run(runTick) is a tail call.

var canceler = runAsync(util.left, asyncAction, function (result) {
return function () {
if (runTick !== localRunTick + 1) {
return;
}
++runTick;
resolved = true;
status = STEP_RESULT;
step = result;
step = result;
run(runTick);
});
};
};
});
// 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;
}
});
return;

Expand Down