0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

110 Commits

Author SHA1 Message Date
Shigeki Ohtsu
81ab78e62e timers: fix not to close reused timer handle
The timer handle is reused when it is unrefed in order to avoid new
callback in beforeExit(#3407). If it is unrefed within a setInterval
callback, the reused timer handle is closed so that setInterval no
longer keep working. This fix does not close the handle in case of
setInterval.

PR-URL: https://github.com/nodejs/node/pull/11646
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-03-22 10:47:52 -07:00
James M Snell
98e54b0bd4 meta: restore original copyright header
A prior io.js era commit inappropriately removed the
original copyright statements from the source. This
restores those in any files still remaining from that
edit.

Ref: https://github.com/nodejs/TSC/issues/174
Ref: https://github.com/nodejs/node/pull/10599
PR-URL: https://github.com/nodejs/node/pull/10155

Note: This PR was required, reviewed-by and approved
by the Node.js Foundation Legal Committee and the TSC.
There is no `Approved-By:` meta data.
2017-03-10 11:23:48 -08:00
John Barboza
9dac165160 timer,domain: maintain order of timer callbacks
PR-URL: https://github.com/nodejs/node/pull/10522
Fixes: https://github.com/nodejs/node/issues/1271
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-02-14 18:54:36 -05:00
asafdav2
b2a77654b7 timer: remove duplicated word in comment
PR-URL: https://github.com/nodejs/node/pull/11323
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-02-13 08:17:57 +09:00
hveldstra
9f6f0f748c timers: fix handling of cleared immediates
If current immediate has no callback, move on to the next one in
the queue.

Fixes: https://github.com/nodejs/node/issues/9756
PR-URL: https://github.com/nodejs/node/pull/9759
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-12-14 10:10:22 -05:00
Michaël Zasso
4d11c2ce5c lib,test: use consistent operator linebreak style
We have a tacit rule that for multiline statements, the operator should
be placed before the linebreak. This commit commit fixes the few
violations of this rule in the code base.
This allows us to enable the corresponding ESLint rule.

PR-URL: https://github.com/nodejs/node/pull/10178
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-12-10 10:46:42 +01:00
Jeremiah Senkpiel
3f1e38c847 timers: use consistent checks for canceled timers
Previously not all codepaths set `timer._idleTimeout = -1` for canceled
or closed timers, and not all codepaths checked it either.

Unenroll uses this to say that a timer is indeed closed and it is the
closest thing there is to an authoritative source for this.

Refs: https://github.com/nodejs/node/pull/9606
Fixes: https://github.com/nodejs/node/issues/9561
PR-URL: https://github.com/nodejs/node/pull/9685
Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-11-22 12:28:41 -05:00
Brian White
42158a0313 timers: fix regression with clearImmediate()
This commit fixes a regression introduced in 0ed8839a27 that caused
additional queued immediate callbacks to be ignored if
`clearImmediate(immediate)` was called within the callback for
`immediate`.

PR-URL: https://github.com/nodejs/node/pull/9086
Fixes: https://github.com/nodejs/node/issues/9084
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-10-14 15:57:25 -05:00
Brian White
0ed8839a27
timers: improve setImmediate() performance
This commit avoids re-creating a new immediate queue object every
time the immediate queue is processed. Additionally, a few functions
are tweaked to make them inlineable.

These changes give ~6-7% boost in setImmediate() performance in the
existing setImmediate() benchmarks.

PR-URL: https://github.com/nodejs/node/pull/8655
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-10-05 03:09:55 -04:00
Brian White
c8c2544cd9
timers: improve setTimeout/Interval performance
This commit improves timers performance by making functions
inlineable and avoiding the creation of extra closures/functions.

This commit also makes setTimeout/Interval argument handling
consistent with that of setImmediate.

These changes give ~22% improvement in the existing 'breadth' timers
benchmark.

PR-URL: https://github.com/nodejs/node/pull/8661
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-10-01 02:58:42 -04:00
yorkie
9b0246b179 timers: remove unreachable code
PR-URL: https://github.com/nodejs/node/pull/8487
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-09-15 14:26:42 +08:00
Jan Schär
1b99093df7 timers: remove unused repeat param in timer_wrap
The `repeat` param in `start(timeout, repeat)` was 0 in all callsites.

PR-URL: https://github.com/nodejs/node/pull/7994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-09 12:26:10 -07:00
Erin Spiceland
7d75338c0e timers: fix cleanup of nested same-timeout timers
For nested timers with the same timeout, we can get into a situation
where we have recreated a timer list immediately before we need to
clean up an old timer list with the same key. Fix: make sure the list
to be deleted is the same instance as the list whose reference was used
to determine that a cleanup is necessary. If it's not the same instance,
a new list with the same key has been created, and it should not be
deleted.

Fixes: https://github.com/nodejs/node/issues/7722

PR-URL: https://github.com/nodejs/node/pull/7827
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Julien Gilli <jgilli@fastmail.fm>
2016-07-29 09:48:45 -07:00
Jeremy Whitlock
5aac4c42da timers: fix processing of nested timers
Whenever a timer is scheduled within another timer, there are a few
known issues that we are fixing:

* Whenever the timer being scheduled has the same timeout value as the
outer timer, the newly created timer can fire on the same tick of the
event loop instead of during the next tick of the event loop
* Whenever a timer is added in another timer's callback, its underlying
timer handle will be started with a timeout that is actually incorrect

This commit consists of
https://github.com/nodejs/node-v0.x-archive/pull/17203 and
https://github.com/nodejs/node-v0.x-archive/pull/25763.

Fixes: https://github.com/nodejs/node-v0.x-archive/issues/9333
Fixes: https://github.com/nodejs/node-v0.x-archive/issues/15447
Fixes: https://github.com/nodejs/node-v0.x-archive/issues/25607
Fixes: https://github.com/nodejs/node/issues/5426
PR-URL: https://github.com/nodejs/node/pull/3063
2016-07-15 11:31:36 -06:00
Andras
6f75b6672c timers: optimize setImmediate()
Save the setImmediate() callback arguments into an array instead of a
closure, and invoke the callback on the arguments from an optimizable
function.

  60% faster setImmediate with 0 args (15% if self-recursive)
  4x faster setImmediate with 1-3 args, 2x with > 3
  seems to be faster with less memory pressure when memory is tight

Changes:
- use L.create() to build faster lists
- use runCallback() from within tryOnImmediate()
- save the arguments and do not build closures for the callbacks

PR-URL: https://github.com/nodejs/node/pull/6436
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-29 11:02:25 +02:00
Andras
6b0f86a8d5 timers: optimize linkedlist
Now uses a new L.create() factory to create access-optimized linkedlist
objects.

PR-URL: https://github.com/nodejs/node/pull/6436
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-06-29 11:02:25 +02:00
Kyle Simpson
9fa25c8ca0 timers: fixing API refs to use safe internal refs
Added safe internal references for 'clearTimeout(..)', 'active(..)', and
'unenroll(..)'. Changed various API refs from 'export.*' to use these
safe internal references.

Now, overwriting the global API identifiers does not create potential
breakage and/or race conditions. See Issue #2493.

PR-URL: https://github.com/nodejs/node/pull/5882
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Fixes: https://github.com/nodejs/node/issues/2493
2016-03-28 16:18:14 -07:00
Jeremiah Senkpiel
d3a75344f5 timers: fix lint from 4fe02e2
Fixes: https://github.com/nodejs/node/issues/5823
Refs: https://github.com/nodejs/node/pull/5793
PR-URL: https://github.com/nodejs/node/pull/5825
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2016-03-21 12:35:12 -04:00
Jeremiah Senkpiel
4fe02e23af timers: give Timeouts a constructor name
Refs: https://github.com/nodejs/node/pull/5792
PR-URL: https://github.com/nodejs/node/pull/5793
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
2016-03-21 11:21:53 -04:00
Brian White
089bef0a81 timers: improve setImmediate() performance
This commit improves setImmediate() performance by moving the
try-finally block that wraps callback execution into a separate
function because currently v8 never tries to optimize functions
that contain try-finally blocks.

With this change, there is a ~20-40% improvement in the included
setImmediate() depth benchmarks. The breadth benchmarks show a slight
improvement.

PR-URL: https://github.com/nodejs/node/pull/4169
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-03-18 19:25:51 -04:00
Jeremiah Senkpiel
67963c8c66 timers: greatly improve code comments
Describes the How and Why of the timers implementation, as well as
adding comments in spots that should allow for an easier understanding
about what is going on.

The timers implementation is very efficient, at a cost.
That cost is readable understandability, and this aims to improve that.

PR-URL: https://github.com/nodejs/node/pull/4007
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2016-02-26 18:07:36 -05:00
Jeremiah Senkpiel
60f8c1acf4 timers: refactor timers
Consolidates the implementation of regular and internal (_unrefActive)
timers.

Also includes a couple optimizations:
- Isolates the try/catch from listOnTimeout() in a new tryOnTimeout().
- Uses a TimersList constructor as the base for linkedlists.

Additionally includes other cleanup and clarification, such as a rename
of "Timer" to "TimerWrap".

PR-URL: https://github.com/nodejs/node/pull/4007
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2016-02-26 18:07:36 -05:00
Rich Trott
7406cd3a59 tools: lint for spacing around unary operators
Enable `space-unary-ops` in `.eslintrc`. This prohibits things like:

    i ++        // use `i++` instead
    typeof(foo) // use `typeof foo` or `typeof (foo)` instead

Ref: https://github.com/nodejs/node/pull/4772#discussion_r51732299
PR-URL: https://github.com/nodejs/node/pull/5063
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-04 10:56:17 -08:00
Anna Henningsen
ac153bd2a6 timers: fail early when callback is not a function
`setTimeout()`, `setInterval()` and `setIntermediate` currently
throw errors when receiving non-function objects as their first
argument, but only do so when trying to execute the callback,
i.e. after the waited time has passed. This may complicate
debugging when a lot of calls to `setTimeout()`/etc. are involved,
so failing as early as possible seems like a good idea.

`setTimeout()` historically ignored an falsy first
argument, while the other functions do not and throw instead.
This patch changes this behaviour to make all three match and
adds remarks in the corresponding documentation.

PR-URL: https://github.com/nodejs/node/pull/4362
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-01-04 14:56:19 +11:00
Andrei Sedoi
fbcd687c08 timers: optimize callback call: bind -> arrow
ES6 arrow functions are much more efficient than `.bind()` functions.

PR-URL: https://github.com/nodejs/node/pull/4038
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-12-02 11:14:28 -05:00
micnic
20285ad177 lib: Consistent error messages in all modules
This commit fixes some error messages that are not consistent with
some general rules which most of the error messages follow.

PR-URL: https://github.com/nodejs/node/pull/3374
Reviewed-By: Roman Reiss <me@silverwind.io>
2015-11-09 20:08:36 +01:00
Fedor Indutny
3eecdf9f14 timers: reuse timer in setTimeout().unref()
Instead of creating new timer - reuse the timer from the freelist. This
won't make the freelist timer active for the duration of `uv_close()`,
and will let the event-loop exit properly.

Fix: #1264
PR-URL: https://github.com/nodejs/node/pull/3407
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-10-20 14:20:24 -04:00
Ryan Graham
bde32f8a4d lib: fix undefined timeout regression
63644dd1cd introduced a regression caused by everyone's favourite
JavaScript feature: undefined < 0 === undefined >= 0.

Add a case to the existing tests to cover this scenario and then add
the check for undefined that makes the test pass.

PR-URL: https://github.com/nodejs/node/pull/3331
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed By: Evan Lucas <evanlucas@me.com>
2015-10-12 19:25:14 -04:00
Rich Trott
47befffc53 lib,test: deprecate _linklist
Deprecate _linklist and add test to confirm internal linklist and
public _linklist are the same.

PR-URL: https://github.com/nodejs/node/pull/3078
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-10-08 17:32:08 -07:00
Rich Trott
070aac4a87 lib: remove redundant code, add tests in timers.js
insert() is only called from one place where there is already a check
that msecs is greater than or equal to zero, so do not repeat the check
inside insert().

timers.active() is not documented and should not be exposed, but since
it is exposed for now, let's test it.

PR-URL: https://github.com/nodejs/node/pull/3143
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2015-10-06 08:28:07 -07:00
Sam Roberts
94e663ac5f timer: ref/unref return self
Most calls to ref() and unref() are chainable, timers should be
chainable, too.

Typical use:

    var to = setTimeout(ontimeout, 123).unref();

PR-URL: https://github.com/nodejs/node/pull/2905
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trevnorris@nodejs.org>
2015-09-16 10:29:13 -07:00
Jeremiah Senkpiel
049b3a3ae2 timers: minor _unrefActive fixes and improvements
This commit addresses most of the review comments in
https://github.com/nodejs/node/pull/2540, which are kept in this
separate commit so as to better preserve the prior two patches as they
landed in 0.12.

This commit:
- Fixes a bug with unrefActive timers and disposed domains.
- Fixes a bug with unrolling an unrefActive timer from another.
- Adds a test for both above bugs.
- Improves check logic, making it stricter, simpler, or both.
- Optimizes nicer with a smaller, separate function for the try/catch.

Fixes: https://github.com/nodejs/node-convergence-archive/issues/23
Ref: https://github.com/nodejs/node/issues/268
PR-URL: https://github.com/nodejs/node/pull/2540
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
2015-09-02 08:14:26 -04:00
Julien Gilli
9724047268 timers: don't mutate unref list while iterating it
Commit 934bfe23a1 had introduced a
regression where node would crash trying to access a null unref timer if
a given unref timer's callback would remove other unref timers set to
fire in the future.

More generally, it makes the unrefTimeout function more solid by not
mutating the unrefList while traversing it.

Fixes: https://github.com/joyent/node/issues/8897

Conflicts:
	lib/timers.js

Fixes: https://github.com/nodejs/node-convergence-archive/issues/23
Ref: https://github.com/nodejs/node/issues/268
PR-URL: https://github.com/nodejs/node/pull/2540
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
2015-09-02 08:14:25 -04:00
Julien Gilli
e5bb66886b timers: Avoid linear scan in _unrefActive.
Before this change, _unrefActive would keep the unrefList sorted when
adding a new timer.

Because _unrefActive is called extremely frequently, this linear scan
(O(n) at worse) would make _unrefActive show high in the list of
contributors when profiling CPU usage.

This commit changes _unrefActive so that it doesn't try to keep the
unrefList sorted. The insertion thus happens in constant time.

However, when a timer expires, unrefTimeout has to go through the whole
unrefList because it's not ordered anymore.

It is usually not large enough to have a significant impact on
performance because:
- Most of the time, the timers will be removed before unrefTimeout is
  called because their users (sockets mainly) cancel them when an I/O
  operation takes place.
- If they're not, it means that some I/O took a long time to happen, and
  the initiator of subsequents I/O operations that would add more timers
  has to wait for them to complete.

With this change, _unrefActive does not show as a significant
contributor in CPU profiling reports anymore.

Fixes: https://github.com/joyent/node/issues/8160

Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>

Conflicts:
	lib/timers.js

Fixes: https://github.com/nodejs/node-convergence-archive/issues/23
Ref: https://github.com/nodejs/node/issues/268
PR-URL: https://github.com/nodejs/node/pull/2540
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
2015-09-02 08:14:25 -04:00
Brian White
5abd4ac079 lib: simplify nextTick() usage
This commit removes unnecessary nextTick() closures and adds some
shared nextTick() callbacks for better re-use.

PR-URL: https://github.com/nodejs/io.js/pull/1612
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>
2015-05-25 10:14:18 -04:00
Fedor Indutny
416499c872 timers: remove redundant code
PR-URL: https://github.com/iojs/io.js/pull/1330
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2015-04-04 02:31:51 +03:00
Fedor Indutny
d22b2a934a timers: do not restart the interval after close
Partially revert 776b73b243.

Following code crashes after backported timer leak fixes:

```javascript
var timer = setInterval(function() {
  clearInterval(timer);
}, 10);
timer.unref();
```

Note that this is actually tested in a `test-timers-unref.js`, and is
crashing only with 776b73b243.

Calling `clearInterval` leads to the crashes in case of `.unref()`ed
timers, and might lead to a extra timer spin in case of regular
intervals that was closed during the interval callback. All of these
happens because `.unref()`ed timer has it's own `_handle` and was used
after the `.close()`.

PR-URL: https://github.com/iojs/io.js/pull/1330
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2015-04-04 02:31:47 +03:00
Julien Gilli
cca5efb086 timers: don't close interval timers when unrefd
This change fixes a regression introduced by commit
0d051238be, which contained a typo that
would cause every unrefd interval to fire only once.

Fixes: https://github.com/joyent/node/issues/8900
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2015-04-04 02:30:33 +03:00
Trevor Norris
0e061975d7 timers: fix unref() memory leak
The destructor isn't being called for timers that have been unref'd.

Fixes: https://github.com/joyent/node/issues/8364
PR-URL: https://github.com/iojs/io.js/pull/1330
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-04-04 02:29:57 +03:00
Jeremiah Senkpiel
776b73b243 timers: cleanup interval handling
Uses `null` as the false-y value for `_repeat` as like other properties.
Removes un-reachable statement in setInterval’s `wrapper()`.

PR-URL: https://github.com/iojs/io.js/pull/1272
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-26 14:17:56 -04:00
Roman Reiss
caf0b36de3 timers: assure setTimeout callback only runs once
Calling this.unref() during the callback of SetTimeout caused the
callback to get executed twice because unref() didn't expect to be
called during that time and did not stop the ref()ed Timeout but
did start a new timer. This commit prevents the new timer creation
when the callback was already called.

Fixes: https://github.com/iojs/io.js/issues/1191
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
PR-URL: https://github.com/iojs/io.js/pull/1231
2015-03-26 17:31:20 +01:00
Ben Noordhuis
33fea6ed5f lib: don't penalize setInterval() common case
The common case is where setInterval() is called with two arguments,
the callback and the timeout.  Specifying optional arguments in
the parameter list forces common case calls to go through an arguments
adaptor stack frame.

PR-URL: https://github.com/iojs/io.js/pull/1221
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-03-20 23:42:26 +01:00
Ben Noordhuis
31da9758a0 lib: don't penalize setTimeout() common case
The common case is where setTimeout() is called with two arguments,
the callback and the timeout.  Specifying optional arguments in the
parameter list forces common case calls to go through an arguments
adaptor stack frame.

PR-URL: https://github.com/iojs/io.js/pull/1221
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-03-20 23:42:26 +01:00
Ruben Verborgh
bd1bd7e38d timer: Improve performance of callbacks
setImmediate, setTimeout, and setInterval were called in an inefficient
way, especially in the presence of arguments.  This optimization
improves their performance, with special cases for up to 4 arguments.
Performance of setImmediate increases with 35%, setInterval with 60%,
setTimeout with 70%.

PR-URL: https://github.com/iojs/io.js/pull/406
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Christian Tellnes <christian@tellnes.com>
2015-03-04 10:08:04 -07:00
cjihrig
0cff0521c3 net: throw on invalid socket timeouts
This commit restricts socket timeouts non-negative, finite
numbers. Any other value throws a TypeError or RangeError.
This prevents subtle bugs that can happen due to type
coercion.

Fixes: https://github.com/joyent/node/issues/8618
PR-URL: https://github.com/joyent/node/pull/8884
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>

Conflicts:
	lib/timers.js
	test/simple/test-net-settimeout.js
	test/simple/test-net-socket-timeout.js
2015-02-13 13:37:24 -05:00
cjihrig
804e7aa9ab lib: use const to define constants
This commit replaces a number of var statements throughout
the lib code with const statements.

PR-URL: https://github.com/iojs/io.js/pull/541
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21 16:21:31 -05:00
Yosuke Furukawa
fd30eb2152 src: fix jslint errors
PR-URL: https://github.com/iojs/io.js/pull/449
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-15 21:21:31 +01:00
isaacs
3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00
Ben Noordhuis
ebf9f297b3 lib: fix guard expression in timer.unref()
Fixes the following assertion on slow systems, like our ARM buildbot:

    $ out/Debug/node test/simple/test-timers-unref.js
    node: ../src/async-wrap-inl.h:101: v8::Handle<v8::Value>
    node::AsyncWrap::MakeCallback(uint32_t, int,
    v8::Handle<v8::Value>*): Assertion `cb_v->IsFunction()' failed.
    Aborted

The reason it only manifests on slow systems is that the test starts
a 1 ms interval timer, then defers timer.unref.bind({}) to the next
tick.  On fast systems, the test completes in under a millisecond,
before the callback is called.

This commit makes timer.unref() check that the receiver actually has
a timeout callback property.

Fixes #13.

PR-URL: https://github.com/iojs/io.js/pull/165
Reviewed-By: Rod Vagg <rod@vagg.org>
2014-12-18 18:24:29 +01:00
Trevor Norris
0d60ab3efe src: remove Async Listener
Async Listener was the name of the user-facing JS API, and is being
completely removed. Instead low level hooks directly into the mechanism
that AL used will be introduced in a future commit.

PR-URL: https://github.com/joyent/node/pull/8110
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Reviewed-by: Fedor Indutny <fedor@indutny.com>
Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
2014-12-09 17:57:12 +01:00