// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'isolates.dart' as isolates;
export 'isolates.dart' show ComputeCallback;
/// The dart:html implementation of [isolate.compute].
@pragma('dart2js:tryInline')
Future<R> compute<M, R>(isolates.ComputeCallback<M, R> callback, M message, { String? debugLabel }) async {
// To avoid blocking the UI immediately for an expensive function call, we
// pump a single frame to allow the framework to complete the current set
// of work.
await null;
return callback(message);
}
-
Martin Kustermann authored
This improves the documentation of the `compute()` function as follows: * Instead of making `compute` a top-level constant, we make it a function. This allows the generated API docs to show a function signature with parameters and their names, making it *much* clearer to users what function is being documented. * We mention that on web-backends this is running `compute()` on the normal eventloop whereas on on native platforms it runs in a separate isolate. * We mention that callback, message and result have to be sendable across isolates. We also mention that they may be copied. * We link to both `Isolate.run` & `SendPort.send` for more information. * We use `M` for the type of `message` instead the rather confusing `Q`.
Unverifiedfc3571ef