Skip to content

Commit

Permalink
refactor(ferry): refactore handleCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kamleithner committed Sep 18, 2022
1 parent d58ebef commit dec0985
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/isolates.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ If you have an authenticated graphql api and need the auth token on both the mai
the main isolate and ferry. For example you can send the new authentication token via that sendPort.
The main isolate would receive it in its `messageHandler` and could persist it, for example via `SharedPreferences`.
You can also establish a two-way communication be creating a `ReceivePort` in the `InitClient` function and send its sendport to
the main isolates messagehandler.
the main isolates messagehandler.

Here's an example on how to wire up SharedPreferences to store
the auth token on the main isolate, refresh it on the ferry isolate when needed, and
send the new token the the main isolate for shared_preferences to store:

https://gist.github.com/knaeckeKami/b11ad83e4b69aa44638815d1471c2ba3
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import FlutterMacOS
import Foundation

import path_provider_macos
import shared_preferences_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}
1 change: 1 addition & 0 deletions packages/ferry/lib/src/isolate/handle_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Future<void> handleCommand(TypedLinkWithCache client, IsolateCommand command,
final stream = client.request(command.request);
final sub = stream.doOnDone(() {
sendPort.send(RequestResponse.done());
cancelEventPort.close();
}).listen((event) {
sendPort.send(RequestResponse.data(event));
});
Expand Down

0 comments on commit dec0985

Please sign in to comment.