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

.map as return value of sunk Promise doesn't get sunk #6307

Closed
p6rt opened this issue Jun 2, 2017 · 4 comments
Closed

.map as return value of sunk Promise doesn't get sunk #6307

p6rt opened this issue Jun 2, 2017 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 2, 2017

Migrated from rt.perl.org#131488 (status was 'rejected')

Searchable as RT131488$

@p6rt
Copy link
Author

p6rt commented Jun 2, 2017

From @zoffixznet

Normally, if you sink a .map, it gets eagerly evaluated​:

  <Zoffix__> m​: <a b c>.map​: &say
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»
  <Zoffix__> m​: for ^1 { <a b c>.map​: &say; $ = 42 }
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»

However, this doesn't happen when the map is the last value of
a sunk Promise​:

  <Zoffix__> m​: start { <a b c>.map​: &say }; sleep 2;
  <camelia> rakudo-moar ef9872​: ( no output )

Workarounds​:

  <Zoffix__> m​: start { @​ = <a b c>.map​: &say }; sleep 2;
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»
  <Zoffix__> m​: start { <a b c>.map​: &say; 42 }; sleep 2;
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»
  <Zoffix__> m​: await start { <a b c>.map​: &say; 42 }
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»
  <Zoffix__> m​: @​ = start { <a b c>.map​: &say; 42 }; sleep 2
  <camelia> rakudo-moar ef9872​: OUTPUT​: «a␤b␤c␤»

@p6rt
Copy link
Author

p6rt commented Jul 14, 2017

From @jnthn

On Fri, 02 Jun 2017 15​:43​:07 -0700, cpan@​zoffix.com wrote​:

Normally, if you sink a .map, it gets eagerly evaluated​:

\<Zoffix\_\_> m&#8203;: \<a b c>\.map&#8203;: &say
\<camelia> rakudo\-moar ef9872&#8203;: OUTPUT&#8203;: «a␤b␤c␤»
\<Zoffix\_\_> m&#8203;: for ^1 \{ \<a b c>\.map&#8203;: &say; $ = 42 \}
\<camelia> rakudo\-moar ef9872&#8203;: OUTPUT&#8203;: «a␤b␤c␤»

However, this doesn't happen when the map is the last value of
a sunk Promise​:

\<Zoffix\_\_> m&#8203;: start \{ \<a b c>\.map&#8203;: &say \}; sleep 2;
\<camelia> rakudo\-moar ef9872&#8203;: \( no output \)

The last statement of a start block is not in sink context, because it becomes the result of the Promise. Sinking a Promise doesn't do anything (and certainly does not block on the result so it can sink it). You should always `await` or `whenever` a Promise or otherwise use its result (`.then(...)` for example), otherwise errors are also lost. So, this works as designed, and the program is at fault for not using the result of the Promise.

Maybe some future Perl 6 version will handle start blocks in sink context differently (for example, giving them an error handling that brings down the program), but that's speculative at this point and we certainly can't do it without causing regression in 6.c.

@p6rt
Copy link
Author

p6rt commented Jul 14, 2017

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

@p6rt
Copy link
Author

p6rt commented Jul 14, 2017

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

@p6rt p6rt closed this as completed Jul 14, 2017
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant