Skip to content

Commit

Permalink
Added Null guarantee
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriano Santos committed Oct 20, 2023
1 parent 191cceb commit 4b3d32e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/src/actors/actor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ class Context {
}

class Value {
late Object _state;
late Object _value;
Optional<Object> _state = Optional.empty();
Optional<Object> _value = Optional.empty();

Object get state {
Optional<Object> get state {
return _state;
}

Object get value {
Optional<Object> get value {
return _value;
}

Value withReponse<R extends GeneratedMessage>(R response) {
_value = response;
_value = Optional.of(response);
return this;
}

Value withState<S extends GeneratedMessage>(S newState) {
_state = newState;
_state = Optional.of(newState);
return this;
}
}
Expand Down
23 changes: 17 additions & 6 deletions lib/src/stateful_named_actor_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 4b3d32e

Please sign in to comment.