stop method
Stop server
Implementation
Future<void> stop({bool wait = true}) async {
if (_startIsolate == null || _stopIsolate != null) {
return;
}
_stopIsolate = await Isolate.spawn((Map data) {
Pointer<Void> implementation =
Pointer<Void>.fromAddress(data["implementation"] as int);
SendPort port = data["port"] as SendPort;
DynamicLibrary library =
DynamicLibrary.open(data["libraryPath"] as String);
Pointer<Pointer<Void>> exception =
WebFrameworkException.createException();
StopWebFrameworkServerDart function = library.lookupFunction<
StopWebFrameworkServerC,
StopWebFrameworkServerDart>("stopWebFrameworkServer");
function.call(implementation, true, exception);
port.send(exception.address);
}, {
"implementation": _implementation.address,
"libraryPath": _handler.libraryPath,
"port": _stopPort.sendPort
});
if (wait) {
Pointer<Pointer<Void>> exception =
Pointer<Pointer<Void>>.fromAddress(await _stopPort.first as int);
_stopIsolate?.kill(priority: Isolate.immediate);
_stopIsolate = null;
WebFrameworkException.checkException(exception, _handler);
} else {
_stopPort.first.then((address) {
Pointer<Pointer<Void>> exception =
Pointer<Pointer<Void>>.fromAddress(address as int);
_stopIsolate?.kill(priority: Isolate.immediate);
_stopIsolate = null;
WebFrameworkException.checkException(exception, _handler);
});
}
}