joyent/node — Issue #2395: proposal: Deadline Exceeded Error
Author: koichik
Created: 2011-12-21 10:42:29+00:00
State: open

Unlike a Web browser, Node has never provided a way to terminate a long-running script breaking an event loop. This proposal offers the way to terminate long-running script based on Domains (#2134).

- Add `deadline` property to `Domain` object.
It indicates the limit of each execution time until returning to an event loop.
If the value is `0`, the script can run indefinitely.
Its initial value is inherited from caller's `Domain`.

- When script does not return to an event loop even after it exceeds deadline, the execution will be forced to terminate.
Then `'error'` event is emitted on the `Domain` object.

example:

```javascript
var myDomain = domains.createDomain(null, function(arg) {
for (;;); // Loop forever
});
myDomain.deadline = 1000; // Sets deadline to one second
myDomain.on('error', function(err) {
// Here is called one second later
});
```

Thoughts?