Skip to content

Commit

Permalink
Add timeout parameter to requestToRust function.
Browse files Browse the repository at this point in the history
  • Loading branch information
cipherchabon committed Nov 2, 2023
1 parent aaf3879 commit 8c93865
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions flutter_ffi_plugin/lib/rinf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ class Rinf {
/// this function will return a failed `RustResponse` object.
/// You can see the usage example at
/// https://pub.dev/packages/rinf/example.
Future<RustResponse> requestToRust(RustRequest rustRequest) async {
Future<RustResponse> requestToRust(
RustRequest rustRequest, {
Duration timeout = const Duration(seconds: 60),
}) async {
final id = _requestIdGenerator.generateId();
final requestUnique = RustRequestUnique(id: id, request: rustRequest);
api.requestToRust(requestUnique: requestUnique);
final future = _responseBroadcaster.stream.firstWhere((responseUnique) {
return responseUnique.id == id;
});
final responseUnique = await future.timeout(
const Duration(seconds: 60),
timeout,
onTimeout: () {
return RustResponseUnique(
id: id,
Expand Down

0 comments on commit 8c93865

Please sign in to comment.