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

Allow a value of 0 with :vent-at #5424

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Allow a value of 0 with :vent-at #5424

wants to merge 2 commits into from

Conversation

lizmat
Copy link
Contributor

@lizmat lizmat commented Oct 16, 2023

Hopefully fixing #5358

@lizmat
Copy link
Contributor Author

lizmat commented Oct 16, 2023

@amano-kenji @AlexDaniel could you check this out the coming days so that it can make the 2023.10 release due this Thursday?

@amano-kenji
Copy link

I will test this next morning.

@amano-kenji
Copy link

I tried to test it. I built it with

perl Configure.pl --gen-moar --gen-nqp --backend=moar

But, I can't find rakudo executable anywhere.

When I call

multi method throttle(Supply:D:
      Int()  $elems,
      Callable:D $process,
      Real() $delay = 0,
      :$scheduler   = $*SCHEDULER,
      :$control,
      :$status,
      :$bleed,
      :$vent-at,
    )

I want only one process to be executed at a time, and while the process is being executed, I want the supply to drop all incoming messages. Does vent-at(0) do that?

@lizmat
Copy link
Contributor Author

lizmat commented Oct 18, 2023

That's the idea. If you also specify :bleed of course?

@amano-kenji
Copy link

amano-kenji commented Oct 19, 2023

If I also specify :bleed, while process is busy, I want the supply to send everything to bleed which will get rid of excess.

@amano-kenji
Copy link

If that works properly as expected, then I think it should be okay to merge it without us.

@lizmat
Copy link
Contributor Author

lizmat commented Oct 19, 2023

If that works properly as expected, then I think it should be okay to merge it without us.

That's it: I didn't test it, as I don't really have an easy test case.

Anyway, it is too late for the 2023.10 release, which will be today.

@amano-kenji
Copy link

How can I test this without installing rakudo?

@ab5tract
Copy link
Collaborator

@amano-kenji You have to use this git repo checked out to the branch of this PR (lizmat-vet-0). First you run perl Configure.pl --gen-moar --gen-nqp --backends=moar and then run make. This will create executables in the directory. No installation necessary.

@amano-kenji
Copy link

amano-kenji commented Oct 21, 2023

I got rakudo-m executable which seemed to be what I wanted.

I executed this.

my $supplier = Supplier.new;

my $chan = $supplier.Supply.throttle(1, -> $a { sleep 5; $a; }, :bleed(Supplier.new), :vent-at(0)).Channel;

start {
  for [1..*] {
    sleep 0.1;
    $supplier.emit($_);
  }
}

react {
  whenever $chan {
    say $_.result;
  }
}

The output was

1
51
101
151
...

It seems to do what I want, but I will have to see whether this is performant.

@ab5tract
Copy link
Collaborator

ab5tract commented Dec 6, 2023

FWIW I was unable to achieve the behavior that @amano-kenji reported when using this branch on macOS 14.

@ab5tract
Copy link
Collaborator

ab5tract commented Mar 23, 2024

I've rebased this against current main and still unfortunately do not get the expected results:

~/c/r/z/rakudo ((6435e28b))
> ./rakudo-m ~/code/raku/scripts/ventatzeroraku/vent-at-zero.raku
1
49
97
145
194
242
291

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

Successfully merging this pull request may close these issues.

None yet

4 participants