inline static method

Future inline(
  1. IsolateJob job, [
  2. App? app
])

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.
  • app: Optional app instance, reserved for future use.

Example:

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

Implementation

static Future<dynamic> inline(IsolateJob job, [App? app]) 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;
}