sendCmd method

void sendCmd(
  1. String command, {
  2. Map<String, Object?>? data,
  3. JSObject? transfer,
})

Send a structured command to the Web Worker.

Convenience method for sending commands with optional data payload and transferable objects. Handles JS interop automatically.

Parameters:

  • command: Command string for the worker to process
  • data: Optional data payload
  • transfer: Optional transferable objects (ArrayBuffers, etc.)

Usage: {@tool snippet example/web_example.dart} {@end-tool}

Implementation

void sendCmd(
  String command, {
  Map<String, Object?>? data,
  JSObject? transfer,
}) {
  final payload = <String, Object?>{...?data, 'command': command};
  if (transfer != null) {
    postMessage(payload.jsify(), transfer);
  } else {
    postMessage(payload.jsify());
  }
}