You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should ensure that a user can't write code like this:
usingSystem;usingAkka.Actor;usingAkka.Event;usingAkka.Actor.Stash;publicclassStashExampleActor:ReceiveActor,IWithStash{publicIStashStash{get;set;}privatereadonlyILoggingAdapter_log=Context.GetLogger();publicStashExampleActor(){// Initial state is WaitingForDataWaitingForData();}privatevoidWaitingForData(){Receive<string>(msg =>{_log.Info($"Received message: {msg}. Transitioning to Processing state and stashing.");// Stash the message twiceStash.Stash();Stash.Stash();// illegal - means we're going to create a duplicate messageBecome(Processing);Self.Tell("ContinueProcessing");// Move to next state to process the stashed messages});}privatevoidProcessing(){Receive<string>(msg =>{_log.Info($"Received message: {msg} while in Processing state.");UnstashAll();Become(WaitingForData);});}
However, the analyzer also needs to be sophisticated enough to know that this code is not that:
usingSystem;usingAkka.Actor;usingAkka.Event;usingAkka.Actor.Stash;publicclassConditionalStashExampleActor:ReceiveActor,IWithStash{publicIStashStash{get;set;}privatereadonlyILoggingAdapter_log=Context.GetLogger();publicConditionalStashExampleActor(){// Initial state is WaitingForDataWaitingForData();}privatevoidWaitingForData(){Receive<string>(msg =>{_log.Info($"Received message: {msg}");// Conditional branching for stashing based on message contentif(msg=="StashCondition1"){_log.Info("Condition 1 met, stashing message.");Stash.Stash();}elseif(msg=="StashCondition2"){_log.Info("Condition 2 met, stashing message.");Stash.Stash();}else{_log.Info("No stashing condition met, processing message immediately.");// Perform processing directly, no stashing}// Transition to Processing state after conditionally stashingBecome(Processing);Self.Tell("ContinueProcessing");// Move to next state to process any stashed messages});}privatevoidProcessing(){Receive<string>(msg =>{_log.Info($"Processing state received message: {msg}");UnstashAll();Become(WaitingForData);});}protectedoverridevoidPreStart(){_log.Info("ConditionalStashExampleActor started.");}protectedoverridevoidPostStop(){_log.Info("ConditionalStashExampleActor stopped.");}}
There are multiple Stash.Stash() calls occurring inside the same Receive<T>, but they are cleanly separated via conditional branches - and therefore should not trigger this rule.
The text was updated successfully, but these errors were encountered:
We should ensure that a user can't write code like this:
However, the analyzer also needs to be sophisticated enough to know that this code is not that:
There are multiple
Stash.Stash()
calls occurring inside the sameReceive<T>
, but they are cleanly separated via conditional branches - and therefore should not trigger this rule.The text was updated successfully, but these errors were encountered: