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

node:timers/promises setInterval not working #26499

Closed
jefbarn opened this issue Oct 23, 2024 · 4 comments
Closed

node:timers/promises setInterval not working #26499

jefbarn opened this issue Oct 23, 2024 · 4 comments
Labels
bug Something isn't working correctly good first issue Good for newcomers node compat

Comments

@jefbarn
Copy link

jefbarn commented Oct 23, 2024

Version: Deno 2.0.2

Example straight from the docs (https://docs.deno.com/api/node/timers/promises/~/setInterval)

import {
  setInterval,
} from 'node:timers/promises';

const interval = 100;
for await (const startTime of setInterval(interval, Date.now())) {
  const now = Date.now();
  console.log(now);
  if ((now - startTime) > 1000)
    break;
}
console.log(Date.now());
error: Uncaught (in promise) TypeError: The "callback" argument must be of type function. Received type number (100)
    at __node_internal_ (ext:deno_node/internal/validators.mjs:283:13)
    at setInterval (node:timers:35:3)
    at ext:deno_node/internal/util.mjs:97:15
    at new Promise (<anonymous>)
    at setInterval (ext:deno_node/internal/util.mjs:82:12)

@littledivy littledivy added bug Something isn't working correctly node compat labels Oct 24, 2024
@bartlomieju bartlomieju added the good first issue Good for newcomers label Oct 24, 2024
@cu8code
Copy link
Contributor

cu8code commented Oct 25, 2024

Hi @bartlomieju @littledivy, this is my first time contributing to Deno. I’ve successfully built the project, And I’m encountering the same error when trying to run the above code with the new build. Could someone point me in the right direction to resolve this issue? I’d really appreciate the help! Thanks in advance!

@Gaurav23V
Copy link

@cu8code I think deno node compatibility layer might be incorrectly resolving the node:times/promises to the traditional timers module since:
Traditional: setInterval(callback, delay, ...args)
Promises: setInterval([delay[, value[, options]]])

@bartlomieju @littledivy I would also like to look at the issue further and work on a fix if you could assign it to me.

@marvinhagemeister
Copy link
Contributor

For folks wanting to tackle this: The issue is here where we're trying to promisify the existing setInterval implementation, whereas in node the promisified variant is a completely different implementation with different arguments, etc.

setInterval: promisify(setInterval),

@cu8code
Copy link
Contributor

cu8code commented Oct 29, 2024

@marvinhagemeister thanks will look into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly good first issue Good for newcomers node compat
Projects
None yet
Development

No branches or pull requests

6 participants