gen_stage icon indicating copy to clipboard operation
gen_stage copied to clipboard

Adds support for handle_continue/2 to gen_stage

Open hazardfn opened this issue 5 years ago • 8 comments

  • {:continue, _term} instructions can now be returned as one would expect from gen_server.
  • :hibernate is now supported on init similar to gen_server.

Attempts to revive #227

hazardfn avatar Oct 08 '20 18:10 hazardfn

The :continue tests will only work OTP 21+, not sure what the best strategy is for limiting these tests to those versions...

EDIT: Added a compile time conditional that checks the OTP major version, if there's a better way let me know! 😃

hazardfn avatar Oct 08 '20 18:10 hazardfn

The failing test seems to be inherently flakey - I can reproduce on master. Not sure what's causing it but running mix test on a loop it occasionally shows up, can investigate separately:

Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ for i in 1 2 3 4 5; mix test; end
                                                                                                                                                              
Compiling 3 files (.ex)
................................................................................................................................................................................................

Finished in 6.0 seconds
192 tests, 0 failures

Randomized with seed 355674
................................................................................................................................................................................................

Finished in 6.0 seconds
192 tests, 0 failures

Randomized with seed 77758
.....................................................................................................

  1) test producer_consumer callbacks producer handle_cancel/3 on consumer down (GenStageTest)
     test/gen_stage_test.exs:1553
     Assertion failed, no matching message after 500ms
     The following variables were pinned:
       ref = #Reference<0.3941081809.3725066241.213827>
       consumer = #PID<0.589.0>
     Showing 2 of 2 messages in the mailbox
     code: assert_receive {:producer_consumer_cancelled, {^consumer, ^ref}, {:down, :killed}}
     mailbox:
       pattern: {:producer_consumer_cancelled, {^consumer, ^ref}, {:down, :killed}}
       value:   {:consumer_subscribed, {#PID<0.588.0>, #Reference<0.3941081809.3725066241.213827>}}

       pattern: {:producer_consumer_cancelled, {^consumer, ^ref}, {:down, :killed}}
       value:   {:producer_consumer_cancelled, {#PID<0.589.0>, #Reference<0.3941081809.3725066241.213827>}, {:down, :noproc}}
     stacktrace:
       test/gen_stage_test.exs:1560: (test)

..........................................................................................

Finished in 6.7 seconds
192 tests, 1 failure

Randomized with seed 791161
................................................................................................................................................................................................

Finished in 6.0 seconds
192 tests, 0 failures

Randomized with seed 199756
................................................................................................................................................................................................

Finished in 6.0 seconds
192 tests, 0 failures

Randomized with seed 937796

hazardfn avatar Oct 08 '20 18:10 hazardfn

Rebased for #265

hazardfn avatar Oct 19 '20 06:10 hazardfn

@josevalim is there something I need to do to move this forward?

hazardfn avatar Jan 11 '21 14:01 hazardfn

Hi @hazardfn, apparently this fell under the cracks, sorry about that. I will try to save some time to review it this week but it may take a while because there are quite some factors to consider here. In any case, thanks for the PR and the ping!

josevalim avatar Jan 11 '21 14:01 josevalim

Would love this feature. Anything I can do to help test/QA/review?

acco avatar Jun 07 '21 22:06 acco

Just checking in to say I won't have as much time as I thought tonight, will post here when I'm able to actually take a bite out of this.

hazardfn avatar Jan 10 '22 21:01 hazardfn

This would be incredible to have access to.

isaacsanders avatar Feb 01 '22 17:02 isaacsanders

Closed in favour of https://github.com/elixir-lang/gen_stage/pull/300.

hazardfn avatar May 12 '23 09:05 hazardfn