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

KillSwitches: flow stage from CancellationToken #3568

Merged
merged 3 commits into from
Aug 18, 2018

Conversation

Horusiath
Copy link
Contributor

@Horusiath Horusiath commented Aug 9, 2018

This PR introduces an extension method, that allows to produce a stage (similar in design to SharedKillSwitch) from CancellationToken:

var cts = new CancellationTokenSource();

source
.Via(cts.Token.AsFlow<string>(cancelGracefully: true))
.RunForEach(Console.WriteLine, materializer)

cancelGracefully parameter defines if calling Cancel on token should cause stream shutdown in graceful way (via Complete) or as a failure (via OperationCanceledException).

@marcpiechura
Copy link
Contributor

@Horusiath api approval is missing and all tests are failing

System.InvalidCastException : Unable to cast object of type 'CancellableKillSwitchStage1[System.Int32]' to type 'Akka.Streams.Stage.IGraphStageWithMaterializedValue2[Akka.Streams.Shape,System.Object]'.
at Akka.Streams.Stage.GraphStageWithMaterializedValue2.<.ctor>b__2_0() at System.Lazy1.CreateValue()
at System.Lazy1.LazyInitValue() at Akka.Streams.Dsl.Source2.ViaMaterialized[TOut2,TMat2,TMat3](IGraph2 flow, Func3 combine)
at Akka.Streams.Tests.Dsl.FlowKillSwitchSpec.<A_CancellationToken_flow_must_complete_immediately_flows_materialized_after_switch_shutdown>b__28_0()
at Akka.Streams.TestKit.Tests.Utils.<>c__DisplayClass3_0.b__0()
at Akka.Streams.TestKit.Tests.Utils.AssertAllStagesStopped[T](AkkaSpec spec, Func`1 block, IMaterializer materializer)

@Horusiath Horusiath force-pushed the cancellation-token-kill-switch branch from ddc4626 to a6dba4e Compare August 15, 2018 11:10
Copy link
Contributor

@marcpiechura marcpiechura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@marcpiechura marcpiechura merged commit aa01127 into akkadotnet:dev Aug 18, 2018
@Aaronontheweb Aaronontheweb added this to the 1.3.9 milestone Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants