inline static method

Future inline(
  1. IsolateJob job
)

Executes a standalone async job inside a fresh isolate and returns its result.

This is useful for one-off isolate execution without defining a full Queueable type.

Parameters:

  • job: The async function to run in the isolate.

Example:

QueueJob.inline(() async {
  return 'ran in isolate';
}).then((result) => print(result));

Implementation

static Future<dynamic> inline(IsolateJob job) async {
  final receivePort = ReceivePort();

  await Isolate.spawn((SendPort sendPort) async {
    final response = await job();
    sendPort.send(response);
  }, receivePort.sendPort);

  final result = await receivePort.first;

  receivePort.close();
  return result;
}