question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Result of async.timeout() only works the first time you call it.

See original GitHub issue

What version of async are you using? 2.4.0

Which environment did the issue occur in (Node version/browser version) Node.js 4.7.0

What did you do? Please include a minimal reproducable case illustrating issue.

const async = require('async');

var asyncFn = function (i, done) {
    if (i < 1) {
        setTimeout(done, 200);
    } else {
        setImmediate(done);
    }
};

// wrap function once, call 10 times
var timeoutFn = async.timeout(asyncFn, 100);
var j = 0;
async.whilst(
    function () {
        return j < 10;
    },
    function (done) {
        timeoutFn(j++, function (err) {
            console.log('Test 1 #' + j, err);
            done();
        });
    },
    function (err) {
    }
);

What did you expect to happen? Should only get timeout error the first time it’s called.

What was the actual result? Timeout occurs every time it’s called, even though the underlying function only takes too long the first time.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
hargasinskicommented, May 21, 2017

Hi @acjohnso25, I believe you’re right that this is bug. It should only give a ETIMEDOUT error on the first call. Thanks for the report, we’ll fix as soon as possible.

0reactions
aearlycommented, May 22, 2017

Fixed in v2.4.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combination of async function + await + setTimeout
The result is an asynchronous call that does not run more often than twice a second, with a timeout of 5 seconds in...
Read more >
How to Add a Timeout Limit to Asynchronous JavaScript ...
In order to create the timeout, we will use an asynchronous function that takes in a Promise, as well as a time limit....
Read more >
On awaiting a task with a timeout in C# - The Old New Thing
Say you have an awaitable object, and you want to await it, ... The value in something is the result of GetSomethingAsync() or...
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
setTimeout takes two arguments: the function it will run asynchronously, and the amount of time it will wait before calling that function. In ......
Read more >
setTimeout() - Web APIs | MDN
Working with asynchronous functions ... setTimeout() is an asynchronous function, meaning that the timer function will not pause execution of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found