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

Supply.throttle should return a Supply of pairs #5573

Open
p6rt opened this issue Aug 15, 2016 · 2 comments
Open

Supply.throttle should return a Supply of pairs #5573

p6rt opened this issue Aug 15, 2016 · 2 comments
Labels
RFC

Comments

@p6rt
Copy link

@p6rt p6rt commented Aug 15, 2016

Migrated from rt.perl.org#128937 (status was 'open')

Searchable as RT128937$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Aug 15, 2016

From liukan@360.cn

Supply.throttle returns a Supply of promises, which in practice may be inadequate. It should return a Supply of pairs, keys being the elements, value being the corresponding Promises. Consider the following senario,

my @​a = 1 .. 10;
my $c = -> {
  if $i == 10.rand { die 'boom' }
  if $i == 10.rand { while 1 {} }
  $_;
};

my $s = Supply.from-list( |@​a ).throttle​: 5, -> $i { &$c( $i ) };

as is, we have no way of knowing which element's corresponding promise failed, not having implemented the logic inside $c.

To circumvent this limitation, one could perceivably do the following, which is combersome.

my $s2 = Supply.from-list( |@​a ).throttle​: 5, -> $i { $i => start { &$c( $i ) } };

Furthermore, throttle should provide a timeout logic. Without it, to implement something equivalent, which is just convoluted.

my $s3 = Supply.from-list( |@​a ).throttle​: 5, -> $i {
  my $p = start { &$c( $i ) };
  await $timeout
  ?? Promise.anyof​: $p, Promise.in​: $timeout
  !! Promise.allof​: $p;
  return $i => $p;
}

The code is also not stable when the resulting supply is tapped. when the thrott
le limit exceeds a cerntain threshold, it just hangs.

- kan
________________________________
From​: å��å��
Sent​: Friday, August 12, 2016 3​:35 PM
To​: rakudobug@​perl.org
Subject​: [perl #​128906]

[15​:01] <kanl> Supply . throttle returns a supply of promises. How does each promise correspond to the original items? e.g. my $s = Supply.from-list( |@​a ).throttle​: 3, -> $v { do-something-with( $a ) }; $s.tap​: -> $v { how-to-figure-out-relation-here() }
[15​:04] <kanl> this matters because when running a number of things in parallel, one supposedly would need to know whose promise got kept and whose got broken, not just which.
[15​:15] <kanl> i don't suppose it's safe to stick things into a hash inside throttle's pointy block, not knowing it's act() or tap(), Someone care to share, please?
[15​:17] == sssd [~ac1f0106@​38.72.195.196] has quit [Quit​: http://www.kiwiirc.com/ - A hand-crafted IRC client]
[15​:20] <kanl> m​: my $s = Supply.from-list(^6).throttle​: 3, { sleep 3; die if $_ == 1 }; $s.act​: -> $v { $v.status.say }; $s.wait;
[15​:20] <+camelia> rakudo-moar c587b9​: OUTPUT«Keptâ�¤Brokenâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Memory allocation failed; could not allocate 4 bytesâ�¤Â»
[15​:21] <kanl> m​: my $s = Supply.from-list(^6).throttle​: 3, { sleep 3; die if $_ == 1 }; $s.act​: -> $v { $v.status.say }; $s.wait;
[15​:21] <+camelia> rakudo-moar c587b9​: OUTPUT«Brokenâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Memory allocation failed; could not allocate 32 bytesâ�¤Memory allocation failed; could not allocate 4 bytesâ�¤Â»
[15​:21] <kanl> m​: my $s = Supply.from-list(^6).throttle​: 3, { sleep 3; die if $_ == 1 }; $s.act​: -> $v { $v.status.say }; $s.wait;
[15​:21] <+camelia> rakudo-moar c587b9​: OUTPUT«Keptâ�¤Brokenâ�¤Keptâ�¤Keptâ�¤Memory allocation failed; could not allocate 4 bytesâ�¤Â»
[15​:22] == TheLemonMan [~root@​unaffiliated/thelemonman] has joined #perl6
[15​:22] <kanl> The same code produces weirder results on my machine.
[15​:24] == labster [~Adium@​miraheze/Labster] has joined #perl6
[15​:25] <gfldex> m​: my $s = Supply.from-list(^6).throttle​: 3, { sleep 3; Failure.new("booboo") if $_ == 1 }; $s.act​: { .status.say }; $s.wait;
[15​:25] <+camelia> rakudo-moar c587b9​: OUTPUT«Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Â»
[15​:25] == camelia [~p6eval@​ns1.niner.name]
[15​:25] == realname : combined, experimental evalbot
[15​:25] == channels : +#perl6
[15​:25] == server : leguin.freenode.net [UmeÃ¥, SE, EU]
[15​:25] == account : camelia
[15​:25] == End of WHOIS
[15​:25] <gfldex> m​: my $s = Supply.from-list(^6).throttle​: 3, { sleep 3; Failure.new("booboo") if $_ == 1 }; $s.act​: { .status.say }; $s.wait;
[15​:25] <+camelia> rakudo-moar c587b9​: OUTPUT«Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Keptâ�¤Memory allocation failed; could not allocate 32 bytesâ�¤Â»
[15​:26] <gfldex> nice new bug for jnthn :)
________________________________
[15​:29] == darutoko [~Vandal@​176.209.234.142] has joined #perl6
[15​:31] == wbill [~wbill@​96-38-107-68.dhcp.jcsn.tn.charter.com] has joined #perl6
[15​:31] <kanl> even if said bug is fixed, i still have no way of knowing the broken promise belongs to 1.
[15​:32] <kanl> well, i do, because i put it there. but if i didn't, then how?

- kan

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Aug 15, 2016

@coke - Status changed from 'new' to 'open'

@p6rt p6rt added the RFC label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.