{"id":18335997,"url":"https://github.com/auritylab/isox","last_synced_at":"2025-04-09T19:52:18.667Z","repository":{"id":56833158,"uuid":"311149859","full_name":"AurityLab/isox","owner":"AurityLab","description":"Run your Isolates with bidirectional communication. Isox provides a simple request/reply pattern to communicate with your Isolates.","archived":false,"fork":false,"pushed_at":"2020-12-25T10:33:23.000Z","size":46,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T12:17:53.850Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/isox","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AurityLab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-08T20:36:45.000Z","updated_at":"2023-12-14T11:47:05.000Z","dependencies_parsed_at":"2022-09-08T07:50:48.570Z","dependency_job_id":null,"html_url":"https://github.com/AurityLab/isox","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AurityLab%2Fisox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AurityLab%2Fisox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AurityLab%2Fisox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AurityLab%2Fisox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AurityLab","download_url":"https://codeload.github.com/AurityLab/isox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103902,"owners_count":21048244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T20:05:31.234Z","updated_at":"2025-04-09T19:52:18.651Z","avatar_url":"https://github.com/AurityLab.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Isox\n\nRun your Isolates with bidirectional communication. Isox provides a simple request/reply pattern to communicate with your Isolates.\n\n## Usage\n\n### Full example\n\n```dart\nimport 'package:isox/isox.dart';\n\nvoid main() async {\n  // Start the Isox instance with the isolate.\n  final instance = await Isox.start(_init);\n\n  // Run the add command with 10 as input.\n  await instance.run(addCommand, 10);\n\n  // Close the Isox instance and the corresponding isolate.\n  instance.close();\n}\n\nint _init(IsoxConfig config) {\n  // Add the add command to the config.\n  config.command(addCommand);\n\n  // Return the initial state on this function.\n  return 0;\n}\n\n// Define an add command with the top-level runner function.\n// The name (\"add\" in this case) must be unique!\nconst addCommand = IsoxCommand('add', _exec);\n\nFuture\u003cint\u003e _exec(int input, int state) async =\u003e state = (state + input);\n```\n\n### Initialization\n\nFirst you need to define the initializer top-level function:\n\n```dart\nint _init(IsoxConfig config) {\n  /// ...\n}\n```\n\nThis function returns the initial state within the Isolate. Through the config you can define various things which are\nnecessary to interact with the Isolate later.\n**Note:** This function MUST be top-level, otherwise it will fail to initialize.\n\nNow you need to start the actual Isox instance:\n\n```dart\nvoid main() async {\n  final isox = await Isox.start(_init);\n}\n```\n\nThis requires the previously defined initializer function. This will return the actual IsoxInstance as a future.\n\n### Commands\n\nAs this library provides an abstraction for the bidirectional communication between the main process, and the isolate,\nyou need to define your commands within the Isolate. A command can accept a single input parameter and return a single\nvalue back to the main process.\n\nThe easiest way to define a command is like this:\n\n```dart\n\nconst addCommand = IsoxCommand('add', _exec);\n\n/// The actual function which will be executed on call. \n/// This provides the input parameter and the current state.\nFuture\u003cint\u003e _exec(int input, int state) async =\u003e state = (state + input);\n```\n\n**Note:** The name of the command (\"add\" in this case) MUST be unique!\n\nIf you have a command which returns `void`, the main process won't wait for completion of the command runner. You can\noverride this behavior by passing the `hasResponseOverride` parameter to the IsoxCommand constructor:\n\n```dart\n\nconst addCommand = IsoxCommand('add', _exec, hasResponseOverride: true);\n```\n\n### Registering commands\n\nThe Isolate process needs to be configured to accept a command. This can be done in the initializer function from\nthe [Initialization](#initialization) section.\n\nHere's an example:\n\n```dart\nint _init(IsoxConfig config) {\n  // Add the previously defined add command to the config.\n  config.command(addCommand);\n\n  // ...\n}\n```\n\n**Note:** An exception will be thrown if you try to register to command twice or register a command with the same name!\n\n### Executing commands\n\nAssume we've already initialized an IsoxInstance and the `addCommand` is registered from the previous section. Through\nthe `IsoxInstance` you can run any registered command on the Isolate process.\n\nExample:\n\n```dart\nvoid main() async {\n  // ...\n\n  // Will run the addCommand with '10' as input.\n  final response = await instance.run(addCommand, 10);\n}\n```\n\nThe output will be returned as a future from the `run` method.\n\n### State\n\nAs you can keep the Isox instance alive, you may need to persist various values through multiple command calls.\n\nYou can provide an initial state through the initializer function like this:\n\n```dart\nint _init(IsoxConfig config) {\n  // Provide 0 as initial state.\n  return 0;\n}\n```\n\nThe state can be access on each command like this:\n\n```dart\n\nconst addCommand = IsoxCommand('add', _exec);\n\nFuture\u003cint\u003e _exec(int input, int state) async {\n  // Second parameter provides the state.\n  // ... \n}\n```\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[tracker]: https://github.com/AurityLab/isox/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauritylab%2Fisox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauritylab%2Fisox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauritylab%2Fisox/lists"}