exit method
Kills the agent and returns its state value. This is faster than calling
deref
then kill since Dart will elide the copy of the result.
Implementation
Future<T> exit() async {
// TODO(gaaclarke): Add an exit listener to the isolate so the state of all
// Agents can be cleared out.
if (_isolate == null) {
throw StateError('Agent has been killed.');
}
_isolate = null;
ReceivePort receivePort = ReceivePort();
_sendPort.send(_Command(_Commands.exit, sendPort: receivePort.sendPort));
dynamic value = await receivePort.first;
return value as T;
}