subtaskCancelWhenReady method

Future<int> subtaskCancelWhenReady(
  1. int subtask, {
  2. required bool isAsync,
})

Executes subtask.cancel and waits when the operation is non-async.

Implementation

Future<int> subtaskCancelWhenReady(
  int subtask, {
  required bool isAsync,
}) async {
  final value = table.get<WASIComponentSubtask>(_subtaskType, subtask);
  final event = _requestSubtaskCancellation(value, subtask, isAsync: isAsync);
  if (event != null) {
    return event;
  }
  if (isAsync) {
    return wasiComponentSubtaskBlocked;
  }
  return value.waitable.withSyncWaiter(
    () => _waitForResolvedSubtaskEvent(value, subtask),
  );
}