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

Cannot use sleep concurrently #154

Open
MayamaTakeshi opened this issue Oct 24, 2021 · 1 comment
Open

Cannot use sleep concurrently #154

MayamaTakeshi opened this issue Oct 24, 2021 · 1 comment

Comments

@MayamaTakeshi
Copy link

Hi,
based on code from #62
I tried to make sleep to run concurrently like this:

var deasync = require('deasync')

setTimeout(function(){
    deasync.sleep(250)
    console.log("deasync works! (1)");
}, 1)

setTimeout(function(){
    deasync.sleep(250)
    console.log("deasync works! (2)");
}, 1)

but the code hangs.
Is this expected?

@ohadcn
Copy link

ohadcn commented Feb 17, 2022

I have similar problem.
have a look at this code:

`const sleep = require('deasync').sleep;

setInterval(e => {
console.log("1", new Date());
}, 1000);
setInterval(e => {
sleep(2000);
console.log("4", new Date());
}, 4000);
`

the code runs and prints:

1 2022-02-17T13:51:31.060Z
1 2022-02-17T13:51:32.062Z
1 2022-02-17T13:51:33.063Z
1 2022-02-17T13:51:36.064Z <-- here the 1 second interval skipped 2 runs
4 2022-02-17T13:51:36.064Z
1 2022-02-17T13:51:37.065Z
1 2022-02-17T13:51:40.062Z <-- skipped again
4 2022-02-17T13:51:40.062Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants