-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add compute
method to easily run a method in an isolate
#40238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The |
I'm seriously considering adding a static static Future<T> run<T>(FutureOr<T> Function() computation); which runs a function in a new ( With the improvements the VM has made on passing closures and other tricky values to other isolates, and with the |
@lrhn was there any progress on this one, or any new recommendations? |
The |
We have now a |
This is basically a re-post of flutter/flutter#48673, since I was advised to file this on this project instead.
It would be great if dart would offer a standard library method for simply running a method in an isolate, i.e. something along the lines of:
Please note that this example uses IsolateRunner.run from the isolate package.
Flutter provides the compute() method for this.
However, in order to create a library that can also be run in a pure dart setting (i.e. without flutter), we need a method that behaves like
compute
in the dart sdk.Is the method I showed above good enough or are there any disadvantages when using
IsolateRunner.run
instead ofcompute
? For a standard library implementation, we should probably get rid ofIsolateRunner
though or merge it into the sdk.One nice thing about
IsolateRunner
is that we can keep a long lived instance of it and dispatch methods to the isolate when needed and not incur the cost of spawning up an isolate.The text was updated successfully, but these errors were encountered: