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

setTimeout #124

Open
mattbierner opened this issue Sep 21, 2013 · 2 comments
Open

setTimeout #124

mattbierner opened this issue Sep 21, 2013 · 2 comments

Comments

@mattbierner
Copy link
Owner

This is an external api but will require changes be made to the interpreter. I think the timeout should be potentially executed after the execution of a statement.

There is only one executing thread of code at a time but multiple 'threads' need to be active in the program context at a time. Some higher level controller then selects the thread to execute next.

For example:

var x = 0;
var y = 0;
function inc(){ ++x; };
setTimeout(f, 1); // Assume time is a number of statements
// Creates a new 'thread' that will call f.
// Check after setTimeout expr statement done to see if should execute.
// Finds zero so no
++y;
// Check again, finds one so yes.
// f executed before next statement. f thread removed from active threads.
// x is 1 here;
++y;
++y;
@mattbierner
Copy link
Owner Author

Instead of working at a statement level, I think working at source element level will be more clear. After a block of source elements have been evaluated, the 'threads' will be checked to see which one to resume next. Complications are handling errors, debugging, and return values with setTimeout.

The interpreter should not return until the entire computation, all 'threads', have completed. Even if a timeout is set for an extended period of time, the interpreter should enter a dispatch loop like pattern until which time the 'thread' can be executed.

The returned value from the interpreter should be the result from the program body source elements. However 'threads' can effect the values in the main thread and these changes may be reflected in the returned value.

Debugging points will be hit regardless of which 'thread' they are in. Errors will be captures in the 'thread' and ignored, but they can still be broken on for debugging.

@mattbierner
Copy link
Owner Author

Actually this is not specifically required if using newer version of requirejs. However, it may still be worth supporting in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant