callbackToCompleter<T> function

void Function(Object?, T) callbackToCompleter<T>(
  1. Completer<T> completer
)

Returns a function that can be passed to a Node.js-style asynchronous callback that will complete completer with that callback's error or success result.

Implementation

void Function(Object?, T) callbackToCompleter<T>(Completer<T> completer) {
  return allowInterop((Object? error, [T? value]) {
    if (error != null) {
      completer.completeError(error);
    } else {
      completer.complete(value);
    }
  });
}