FLUTTER ECOSYSTEM

maxim-saplin/isolate_pool_2

스레드 풀과 비슷하지만, 이소레이트를 사용하여

isolate_pool_2 프로젝트 이미지
Stars
10
Forks
5
최근 푸시(UTC)
2024. 11. 28.
프로젝트 상태
활성
Maxim Saplin GitHub avatar
GITHUB User

Maxim Saplin ↗

EPAM Systems Europe
언어Dart

기술 주제

사용 중인 의존성

의존성 목록 2 개
  • test개발 의존성—
  • lints개발 의존성—

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

The package provides APIs for creating and keeping active Dart isolates (an isolate pool) ready to receive requests, do the processing and provide results.

The best way to learn how to use the package is to check the provided example... Or clone the repo, open it in VSCode and run unit tests.

Use-case one - pooled jobs (Request <-> Response)

The pool can accept one-time requests (pooled jobs) mimicking Flutter's compute() method. But instead of spawning a new isolate each time it will use one of the available active isolates from the pool. In order to do so you need to inherit PooledJob class, define whatever params are needed as class fields, override the job() method that will be executed on pooled isolate. Use IsolatePool.scheduleJob() and pass an instance of pooled job in order to get it transferred to another isolate, executed and result returned.

Use-case two - persistant remote objects (aka pooled instances)

The second way of using the APIs is to have an instance created in one of the pooled isolates and communicate with it via a proxy instance, It is kind of messaging from the main isolate to one of the isolates in a pool with multiple instances created in multiple isolates, messages and responses properly correlated and arranged via descendants of Action. You can wrap PooledInstanceProxy in a class and mimic RPC kind of communication with PooledInstance in external isolate.

Pooled Instance - How it works

Diagram