# New Ticket Created by 刘刊
# Please include the string: [perl #128937]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=128937 >
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: [email protected]
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 [[email protected]] 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«KeptBrokenKeptKeptKeptMemory
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«BrokenKeptKeptKeptKeptMemory
allocation failed; could not allocate 32 bytesMemory 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«KeptBrokenKeptKeptMemory
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«KeptKeptKeptKeptKeptKeptKeptKept»
[15:25] == camelia [[email protected]]
[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«KeptKeptKeptKeptKeptKeptMemory allocation failed; could not
allocate 32 bytes»
[15:26] <gfldex> nice new bug for jnthn :)
________________________________
[15:29] == darutoko [[email protected]] has joined #perl6
[15:31] == wbill [[email protected]] 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