パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v3.2.1

computer

compute() に似た API を備えた、使いやすい並行ワーカープール。

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
1390
いいね数
63
Pub ポイント
160

パッケージをインストール

flutter pub add computer

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

コンピュータパッケージは、Dartでシンプルかつ効率的な並列ワーカープールを提供し、Flutterの組み込みcompute関数と同様のcompute() APIを提供します。CPU集約的なタスクをメインのイソレートから分離して実行でき、アプリの応答性を向上させます。使いやすさを重視しており、複雑な並行処理管理を抽象化しながら、Android、iOS、macOS、Windows、Linuxなど複数のプラットフォームをサポートしています。データ解析や画像操作、重い計算などのバックグラウンド処理に最適です。

用途

  • バックグラウンドでCPU集約的な操作を実行する
  • UIをブロッキングせずに大規模なデータセットを処理する
  • 画像またはファイルの変換を実行する
  • 長時間実行される数学的計算を実行しています
  • 集中的なタスク中にアプリのパフォーマンスを向上させる

主な機能

  • シンプルな compute() API
  • クロスプラットフォーム対応
  • 自動ワーカープール管理
  • 軽量で統合が簡単
  • 組み込みのエラー処理と再試行

適している対象

  • バックグラウンド計算を必要とする開発者
  • データ処理が集中するアプリ
  • 重いワークロード中に応答性のあるUIを必要とするプロジェクト
  • Flutterのcomputeのドロップイン代替を求めるチーム
  • 複数のデスクトップおよびモバイルプラットフォーム向けアプリケーション

注意事項

  • I/Oバウンドタスクには適していません
  • ワーカーの動作のカスタマイズが限定的
  • 多数の並行タスクでメモリをより多く消費する可能性があります
  • ネットワーク操作よりも、CPU集約的な処理に最適です
  • 隔離間での大規模なデータ転送には注意が必要です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Computer

Computer is a lightweight library for concurrent computations, which provides Flutter's compute like API.

Features

  • Easy to use API
  • No overhead on creating & releasing isolates for each task. Workers initialized on start and ready to solve your tasks
  • Strictly defined number of workers

Note

Computer.shared() is a singleton, use Computer.create() to create new instances

How to use

Computer provides just 3 methods

turnOn()

Before using the Computer you need to turnOn it. This will create workers and initialize them. Then you may use compute() method.

final computer = Computer.create(); //Or Computer.shared()

await computer.turnOn(
  workersCount: 4, // optional, default 2
  verbose: false, // optional, default false
);
compute()

compute will execute your function inside one of the workers. Function may be async. The callback argument must be a top-level or static method of a class.

final result = await computer.compute(
  fib,
  param: 45, // optional
);
turnOff()

If you don't need workers anymore, you can turnOff the Computer. It will destroy workers.

await computer.turnOff();
Errors

ComputerError the parent error for all errors/exceptions in this package

class ComputerError implements Exception {
  final String message;
}

RemoteExecutionError shows up when something goes wrong in task

class RemoteExecutionError extends ComputerError {
  final Capability taskCapability;
}

CancelExecutionError shows up when turnOff is called but task is processing

class CancelExecutionError extends ComputerError {
  final Capability taskCapability;
}

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト