stockfishAsync function

Future<Stockfish> stockfishAsync()

Creates a C++ engine asynchronously.

This method is different from the factory method new Stockfish that it will wait for the engine to be ready before returning the instance.

Implementation

Future<Stockfish> stockfishAsync() {
  if (Stockfish._instance != null) {
    return Future.error(StateError('Only one instance can be used at a time'));
  }

  final completer = Completer<Stockfish>();
  Stockfish._instance = Stockfish._(completer: completer);
  return completer.future;
}