Navigation Menu

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

Weird interaction between sleep() and Promises #3631

Closed
p6rt opened this issue Dec 29, 2014 · 4 comments
Closed

Weird interaction between sleep() and Promises #3631

p6rt opened this issue Dec 29, 2014 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Dec 29, 2014

Migrated from rt.perl.org#123520 (status was 'resolved')

Searchable as RT123520$

@p6rt
Copy link
Author

p6rt commented Dec 29, 2014

From flussence@gmail.com

IRClogs for reference​: http://irclog.perlgeek.de/perl6/2014-12-29#i_9865603

I have this golfed-down example, tested on Rakudo 2014.12 JVM+MoarVM​:

  await Promise.anyof( start({ sleep 2*3; say 3 }),
Promise.in(2*1).then({ say 1 }) ); sleep 2; say 2; sleep 3;

I'd expect that to produce output roughly equivalent to writing​:

  for 1..3 { .say; sleep 2 }

But what happens instead is more like this​:

  sleep 6; say 3; say 1; sleep 2; say 2;

Other stuff I've found​: If I change the start() to a
Promise.in().then(), or swap the order of args to Promise.anyof, it'll
DWIM. Running the example with strace -ff generates 20+ megabytes of
output, which seems a bit fishy.

@p6rt
Copy link
Author

p6rt commented May 4, 2015

From @jnthn

On Mon Dec 29 13​:30​:31 2014, flussence@​gmail.com wrote​:

IRClogs for reference​: http://irclog.perlgeek.de/perl6/2014-12-29#i_9865603

I have this golfed-down example, tested on Rakudo 2014.12 JVM+MoarVM​:

await Promise\.anyof\( start\(\{ sleep 2\*3; say 3 \}\),

Promise.in(2*1).then({ say 1 }) ); sleep 2; say 2; sleep 3;

I'd expect that to produce output roughly equivalent to writing​:

for 1\.\.3 \{ \.say; sleep 2 \}

But what happens instead is more like this​:

sleep 6; say 3; say 1; sleep 2; say 2;

Other stuff I've found​: If I change the start() to a
Promise.in().then(), or swap the order of args to Promise.anyof, it'll
DWIM.

The scheduler was making some bad assumptions that Promise.in things wouldn't go doing things like sleeping or hogging resources for a while. While, of course, if you do that there will eventually be problems with thread exhaustion, there's no reason simple examples like this shouldn't work. So, fixed, and added a test in S17-promise/in.t.

@p6rt
Copy link
Author

p6rt commented May 4, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed May 4, 2015
@p6rt
Copy link
Author

p6rt commented May 4, 2015

@jnthn - Status changed from 'open' to 'resolved'

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

1 participant