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

Cannot rely on Object.keys order #19

Closed
dtex opened this issue Jul 3, 2018 · 2 comments
Closed

Cannot rely on Object.keys order #19

dtex opened this issue Jul 3, 2018 · 2 comments

Comments

@dtex
Copy link
Collaborator

dtex commented Jul 3, 2018

I wanted to submit this before submitting the HR pull request to avoid confusion.

When using Object.keys() to populate the scheduled array in processQueue() we can't trust that V8 will return an array that is sorted by key. Since temporal checks the last member of that array to see if there is anything left in the queue that needs to be run, temporal checks the last member added, not the last member by the scheduled time to execute.

In other words, Temporal assumes that tasks are added in the order that they are expected to execute.

For example, this works:

let temporal = require("temporal");

temporal.delay(5, () => { console.log(5);});
temporal.delay(10, () => { console.log(10);});
\\ 5
\\ 10

But this does not:

let temporal = require("temporal");

temporal.delay(10, () => { console.log(10);}); // Never fires
temporal.delay(5, () => { console.log(5);});
\\ 5

Here's the offending code:

var scheduled = Object.keys(queue);
var last = scheduled.length && +scheduled[scheduled.length - 1];
@dtex
Copy link
Collaborator Author

dtex commented Jul 23, 2018

Storing last in a global and updating anytime task.later is greater seems to solve the problem. I'll do some performance testing on that option.

@dtex
Copy link
Collaborator Author

dtex commented Aug 6, 2018

Here's all the dirt on this issue.

tc39/ecma262#1242

In short, implementations don't match the spec.

@dtex dtex closed this as completed in 48ec56d Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant