close method

Future<void> close()

Stops the worklet and releases the audio context.

Implementation

Future<void> close() async {
  if (_closed) return;
  _closed = true;
  try {
    // Ask the processor to return false so the node is collected, THEN tear
    // the graph down; disconnecting first can leave it running silently.
    _node.port.postMessage('stop'.toJS);
    _node.disconnect();
    _gain.disconnect();
  } on Object {
    // Already gone.
  }
  try {
    await _context.close().toDart;
  } on Object {
    // Already closed.
  }
}