All Projects → fluttervn → isolate_woker

fluttervn / isolate_woker

Licence: MIT license
Library help run flutter tasks in other isolate

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to isolate woker

Coravel
Near-zero config .NET Core micro-framework that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
Stars: ✭ 1,989 (+3800%)
Mutual labels:  background-thread, background-worker
Hangfire
An easy way to perform background job processing in your .NET and .NET Core applications. No Windows Service or separate process required
Stars: ✭ 7,126 (+13872.55%)
Mutual labels:  background-thread, background-worker
PeriodicBackgroundService
Simple implementation of periodic background service with Xamarin.
Stars: ✭ 37 (-27.45%)
Mutual labels:  background-worker
kamisama
Start, monitor, and observe background worker processes, from Ruby.
Stars: ✭ 57 (+11.76%)
Mutual labels:  background-worker
pedax
Reversi Board with edax, which is the strongest reversi engine.
Stars: ✭ 18 (-64.71%)
Mutual labels:  isolate
executorservices
Dart executer services.
Stars: ✭ 17 (-66.67%)
Mutual labels:  isolate
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (-43.14%)
Mutual labels:  isolate
multithread-mpp
This is the best architecture of Kotlin Multiplatform Project I think! This project works on background thread using kotlinx.Coroutines.
Stars: ✭ 16 (-68.63%)
Mutual labels:  background-thread
webapi-backgroundworker-rabbitmq
Sample implementation of a WebApi that publishes messages to RabbitMQ and consume them using a BackgroundWorker.
Stars: ✭ 20 (-60.78%)
Mutual labels:  background-worker

isolate_worker

Build Status

Library help run flutter tasks in other isolate. The library improve from original library: https://github.com/Dreckr/Worker Improvement:

  • Return callback progress for upload/download file
  • Support cancel download/upload file

Usage

Define class:

class DownloadTask implements FileTask<Future<bool>> {
  final Dio dio;
  final String url;
  final String savePath;
  CancelToken cancelToken;

  DownloadTask(
      {@required this.dio, @required this.url, this.savePath, this.taskId});

  @override
  Future<bool> execute() {
    return _doExecute();
  }

  Future<bool> _doExecute() async {
    cancelToken = CancelToken();
    var completer = Completer<bool>();

    try {
      final response = await dio.download(url, savePath,
          cancelToken: cancelToken, onReceiveProgress: taskProgressCallback);

      print('DownloadTask success: $response');
      completer.complete(true);
    } catch (e) {
      print('DownloadTask error: $e');
      completer.completeError(e);
    }

    return completer.future;
  }

  @override
  ActionType actionType = ActionType.download;

  @override
  String taskId;

  @override
  var taskProgressCallback;

  @override
  void handleCancel(String taskId) {
    cancelToken?.cancel('Cancel download $taskId');
  }
}

Use:

Function(TransferProgress progress) progressCallback = (progress) {
      setState(() {
        percent = progress.count / progress.total;
      });
    };

    var saveFolder = await Utils.getDownloadDirectory('Demo/Download');
    final fullPath = '${saveFolder.path}/download.jpg';
    final urlPath = 'https://sample-videos.com/img/Sample-jpg-image-2mb.jpg';
    final dio = Dio();
    var downloadTask = DownloadTask(
        taskId: fullPath, dio: dio, url: urlPath, savePath: fullPath);
    final worker = Worker(poolSize: 1);
    await worker.handle(downloadTask, callback: progressCallback);
    setState(() {
      loading = false;
      imagePath = fullPath;
    });

Please refer to my post on Medium for more details

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].