_isolates_io.dart 661 Bytes
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:isolate';

import 'constants.dart';
import 'isolates.dart' as isolates;

11 12
export 'isolates.dart' show ComputeCallback;

13
/// The dart:io implementation of [isolate.compute].
14 15
@pragma('vm:prefer-inline')
Future<R> compute<M, R>(isolates.ComputeCallback<M, R> callback, M message, {String? debugLabel}) async {
16
  debugLabel ??= kReleaseMode ? 'compute' : callback.toString();
17

18 19 20
  return Isolate.run<R>(() {
    return callback(message);
  }, debugName: debugLabel);
21
}