p-hatan/ mirror

pub repository

mirror.p-hatan.com

isolate_channel

0.6.1

Communication channels for isolates based on Flutter's platform channels

Cached in Iran · Upstream SHA-256 matched

Download archive

Readme

isolate_channel

PubStats Popularity PubStats Rank PubStats Dependents

Communication channels for isolates based on Flutter's platform channels

Features

  • Helper functions to spawn, setup, and connect to isolates
  • Method channels for making method calls to an isolate and receiving the result
  • Event channels for receiving streamed events from an isolate

Usage

In the parent isolate, use the spawnIsolate function to spawn a new isolate and connect to it

final connection = await spawnIsolate(isolateEntryPoint);

In the newly spawned isolate, use the setupIsolate function to set up the isolate for channel communication

void isolateEntryPoint(SendPort? send) {
  final connection = setupIsolate(send);
}

Now create communication channels in both isolates

final methodChannel = IsolateMethodChannel('method_channel', connection);
final eventChannel = IsolateEventChannel('event_channel', connection);

Set up handlers for the channels in the newly spawned isolate

methodChannel.setMethodCallHandler((call) {
  switch (call.method) {
    case 'example_method':
      print(call.arguments);
      return 'World!';
    default:
      return call.notImplemented();
  }
});

eventChannel.setStreamHandler(
  IsolateStreamHandler.inline(
    onListen: (arguments, sink) {
      sink.success(arguments);
      sink.error(
        code: 'error',
        message: 'Something went wrong',
        details: 1234,
      );
      sink.endOfStream();
    },
    onCancel: (arguments) => print('Canceled: $arguments'),
  ),
);

Now you can use the channels to communicate

final result = await methodChannel.invokeMethod('example_method', 'Hello');
final stream = eventChannel.receiveBroadcastStream();

And close the connection when you're done

connection.close();

Connect to a running isolate

Pass an isolate's send port to the connectToIsolate function to connect to it. A send port can be retrieved from an IsolateNameServer.

final connection = await connectToIsolate(send);
Changelog

0.6.1

  • Fixes README

0.6.0

  • Adds onSendPortReady in setupIsolate to support headless restarts
  • The IsolateEntryPoint and setupIsolate functions now accept a nullable send parameter to support headless restarts
  • The connectToIsolate function now supports onExit and onError callback setup

0.5.0

  • Exposes the spawnIsolateConnection function that allows connecting to custom isolates
  • Removes the spawn parameters from the spawnIsolate and spawnUriIsolate functions

0.4.2

  • Updates README to reflect that connectToIsolate returns a Future

0.4.1

  • Loosens constraint on meta

0.4.0

  • Allows passing an IsolateSpawner to support custom isolate implementations such as FlutterIsolate
  • Makes connectToIsolate return a Future so that connection failure can be handled

0.3.0

  • Removes unnecessary type parameters from spawn methods

0.2.2+1

  • Adds README badges

0.2.2

  • Handles more edge cases in IsolateEventChannel

0.2.1

  • Does not cancel handler subscription when onCancel is called in IsolateEventChannel

0.2.0

  • BREAKING: Refactors IsolateException.notImplemented(...) into call.notImplemented()
  • Supports communication between isolates spawned with Isolate.spawnUri
  • EventChannel optimizations

0.1.1

  • Handles exceptions thrown in method call handlers

0.1.0

  • Initial release

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add isolate_channel
pubspec.yaml
name: isolate_channel
description: Communication channels for isolates based on Flutter's platform channels
homepage: https://github.com/IO-Design-Team/isolate_channel
version: 0.6.1

environment:
  sdk: ^3.0.0

dependencies:
  meta: ^1.14.0

dev_dependencies:
  test: ^1.24.0
  rexios_lints: ^17.0.2
  mockito: ^5.4.5
  build_runner: ^2.4.15
  isolate_name_server: ^1.1.0

Version history

VersionPublishedArchiveSHA-256
0.1.02025-03-12T20:14:29.517097ZCached4aef81d4fb8fa36d59821914d4f763471877acb80e748c88095e9b33036b9848
0.1.12025-03-12T23:43:42.024086ZCached5c8795d36a25c31448e2a479861eb28afa3e95906f6bc1c62184af29cfe691f3
0.2.02025-03-17T23:40:13.967232ZCachedb667af2d970626e9df41fcddcdd4fedae009e1148f79e10674b1572e73b6b17f
0.2.12025-03-23T15:16:24.922896ZCached70f80485767374a8c61c6fbde8cc014a7f401915d9ec72d916a077f2fd86bc1c
0.2.22025-03-25T12:20:51.755705ZCachedbafedfbcc1e9796ada179b5dac7043b33eb85d35204b089ca37d480d9c0068df
0.2.2+12025-05-22T19:09:54.952244ZCachedf3d36f783b301e6b312c3450eeb2656b0e7d1db81331af2a151d9083a3f6b18d
0.3.02026-01-13T13:58:13.278991ZCached68191008e3a219bc87cc8cddbcd1e29810bd9f3a0fdc2108b574ccbd9aafda08
0.4.02026-01-21T19:47:00.376423ZCachedef888e59c2b471033f6154ccf54e9f40712c7646ef101f6f91fe55c7d6f1f073
0.4.12026-01-21T19:56:09.600880ZCached000d617d021a608186b468584bbc6df2509ecba048f08510f832fdb9cf7aafbe
0.4.22026-01-27T17:23:36.810700ZCachedd9e706ce2b0d871c9e05dcdf6fc0e35b0ce90c59ebfcdb3aba5d221ba228a087
0.5.02026-02-02T15:55:15.118785ZCached99f991fbfd915017bc99df5fa06fdb70648d977fd2712bcca1527c7609f050a4
0.6.02026-02-02T23:25:51.053139ZCached30116dae19310e3d31706adc5a185070d42ade3fc7ea411b6069df3dc18a1284
0.6.12026-02-06T03:09:16.323997ZCacheda9d3d620695bc984244dafae00b95e4319d6974b2d77f4b9e1eb4f2efe099094

Dependencies

meta "^1.14.0"