Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Unexpected behaviour in Timers api (setInterval, setTimeout) #747

Closed
brentlintner opened this issue Mar 6, 2011 · 5 comments
Closed

Unexpected behaviour in Timers api (setInterval, setTimeout) #747

brentlintner opened this issue Mar 6, 2011 · 5 comments

Comments

@brentlintner
Copy link

Hey all,

Not sure if I am blatantly missing something, but I can not find any resource mentioning the current behaviour of setInterval/setTimeout methods in the Timers api for 0.4.x.

As per the current docs for 0.4.2, setTimeout and setInterval return a id, and can be cleared with clearInterval/clearTimeout.

http://nodejs.org/docs/v0.4.2/api/timers.html

But contrary to that, they apparently now return objects:

setTimeout (for 4000ms) returns:
{ _idleTimeout: 4000,
_onTimeout: [Function],
_idlePrev: { repeat: 4, _idleNext: [Circular], _idlePrev: [Circular], callback: [Function] },
_idleNext: { repeat: 4, _idleNext: [Circular], _idlePrev: [Circular], callback: [Function] },
_idleStart: Sun, 06 Mar 2011 00:55:16 GMT }

setInterval (every 4000ms) returns:
{ repeat: 4, callback: [Function] }

Is this expected or possibly new behaviour? I was able to clear the interval by deleting the callback property, but that I am not sure that is right... so, again, am I missing something?

For reference:

Using: v0.4.2
Platlform: Linux 2.6.35-27 (Ubuntu 10.10) x86_64

Cheers,

@koichik
Copy link

koichik commented Mar 6, 2011

The object which setTimeout() / setInterval() returns is id. You can pass it to clearTimeout() / clearInterval(). Document does not say what type of id.

$ node
> var id = setTimeout(console.log, 10 * 1000, 'Timedout');
> clearTimeout(id);
> 

After 10s, nothing is output.

@brentlintner
Copy link
Author

A big duh comes to mind. I think I need some sleep, because I am not being a good programmer at the moment. Not exactly sure how I came to my initial conclusion now. I must of additionally mixed up the methods when the clearing was not working as well. fail...

Apologies for wasting time, appreciate the reply.

@kav
Copy link

kav commented Jul 12, 2011

I don't know that sounds like a bit of a BS response. A giant object filled with crap and a few circular references is hardly an "ID". While it's true the trivial example works it's a real pain any time this goes async or across user requests.

@bnoordhuis
Copy link
Member

@kav Not sure what you're getting at but if you can present a good use case - preferably as a standalone test case - we can look into it.

EDIT: but an even better idea is to raise it on the nodejs mailing list.

@kav
Copy link

kav commented Jul 12, 2011

Will do.

lyonplus pushed a commit to lyonplus/node that referenced this issue May 22, 2015
PR-URL: nodejs/node#1532

Notable Changes:

* crypto: significantly reduced memory usage for TLS (Fedor Indutny & Сковорода
  Никита Андреевич) nodejs#1529
* net: socket.connect() now accepts a 'lookup' option for a custom DNS
  resolution mechanism, defaults to dns.lookup() (Evan Lucas) nodejs#1505
* npm: Upgrade npm to 2.9.0. See the v2.8.4 and v2.9.0 release notes for
  details. Notable items:
  - Add support for default author field to make npm init -y work without
    user-input (@othiym23) npm/npm/d8eee6cf9d
  - Include local modules in npm outdated and npm update (@ArnaudRinquin)
    npm/npm#7426
  - The prefix used before the version number on npm version is now configurable
    via tag-version-prefix (@kkragenbrink) npm/npm#8014
* os: os.tmpdir() is now cross-platform consistent and will no longer returns a
  path with a trailling slash on any platform (Christian Tellnes) nodejs#747
* process:
  - process.nextTick() performance has been improved by between 2-42% across the
    benchmark suite, notable because this is heavily used across core (Brian White) nodejs#1548
  - New process.geteuid(), process.seteuid(id), process.getegid() and
    process.setegid(id) methods allow you to get and set effective UID and GID
    of the process (Evan Lucas) nodejs#1536
* repl:
  - REPL history can be persisted across sessions if the NODE_REPL_HISTORY_FILE
    environment variable is set to a user accessible file,
    NODE_REPL_HISTORY_SIZE can set the maximum history size and defaults to 1000
    (Chris Dickinson) nodejs#1513
  - The REPL can be placed in to one of three modes using the NODE_REPL_MODE
    environment variable: sloppy, strict or magic (default); the new magic mode
    will automatically run "strict mode only" statements in strict mode
    (Chris Dickinson) nodejs#1513
* smalloc: the 'smalloc' module has been deprecated due to changes coming in V8
  4.4 that will render it unusable
* util: add Promise, Map and Set inspection support (Christopher Monsanto) nodejs#1471
* V8: upgrade to 4.2.77.18, see the ChangeLog for full details. Notable items:
  - Classes have moved out of staging; the class keyword is now usable in strict
    mode without flags
  - Object literal enhancements have moved out of staging; shorthand method and
    property syntax is now usable ({ method() { }, property })
  - Rest parameters (function(...args) {}) are implemented in staging behind the
    --harmony-rest-parameters flag
  - Computed property names ({['foo'+'bar']:'bam'}) are implemented in staging
    behind the --harmony-computed-property-names flag
  - Unicode escapes ('\u{xxxx}') are implemented in staging behind the
    --harmony_unicode flag and the --harmony_unicode_regexps flag for use in
    regular expressions
* Windows:
  - Random process termination on Windows fixed (Fedor Indutny) nodejs#1512 / nodejs#1563
  - The delay-load hook introduced to fix issues with process naming (iojs.exe /
    node.exe) has been made opt-out for native add-ons. Native add-ons should
    include 'win_delay_load_hook': 'false' in their binding.gyp to disable this
    feature if they experience problems . (Bert Belder) nodejs#1433
* Governance:
  - Rod Vagg (@rvagg) was added to the Technical Committee (TC)
  - Jeremiah Senkpiel (@Fishrock123) was added to the Technical Committee (TC)
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants