From 4b3d32e64a286ccfae5f17160c5d75fc30a95cca Mon Sep 17 00:00:00 2001 From: Adriano Santos Date: Fri, 20 Oct 2023 12:16:22 -0300 Subject: [PATCH] Added Null guarantee --- lib/src/actors/actor.dart | 12 ++++++------ lib/src/stateful_named_actor_handler.dart | 23 +++++++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/src/actors/actor.dart b/lib/src/actors/actor.dart index 04ca4bc..a5a1dcd 100644 --- a/lib/src/actors/actor.dart +++ b/lib/src/actors/actor.dart @@ -20,24 +20,24 @@ class Context { } class Value { - late Object _state; - late Object _value; + Optional _state = Optional.empty(); + Optional _value = Optional.empty(); - Object get state { + Optional get state { return _state; } - Object get value { + Optional get value { return _value; } Value withReponse(R response) { - _value = response; + _value = Optional.of(response); return this; } Value withState(S newState) { - _state = newState; + _state = Optional.of(newState); return this; } } diff --git a/lib/src/stateful_named_actor_handler.dart b/lib/src/stateful_named_actor_handler.dart index 43f71ce..4b084ef 100644 --- a/lib/src/stateful_named_actor_handler.dart +++ b/lib/src/stateful_named_actor_handler.dart @@ -79,13 +79,24 @@ class StatefulNamedActorHandler implements ActorHandler { Value resultValue = result.value; spawn_protocol.Context updatedCtx = spawn_protocol.Context.create(); - updatedCtx.state = Any.pack(resultValue.state as GeneratedMessage); - return spawn_protocol.ActorInvocationResponse.create() - ..actorName = invocation.actor.name - ..actorSystem = invocation.actor.system - ..updatedContext = updatedCtx - ..value = Any.pack(resultValue.value as GeneratedMessage); + if (resultValue.state.isPresent) { + updatedCtx.state = + Any.pack(resultValue.state.value as GeneratedMessage); + } + + spawn_protocol.ActorInvocationResponse resp = + spawn_protocol.ActorInvocationResponse.create(); + + resp.actorName = invocation.actor.name; + resp.actorSystem = invocation.actor.system; + resp.updatedContext = updatedCtx; + + if (resultValue.value.isPresent) { + resp.value = Any.pack(resultValue.value.value as GeneratedMessage); + } + + return resp; } }