loadState method

  1. @override
Future<int> loadState(
  1. String path
)
override

Restores a state written by saveState; returns the tokens it holds. Failures throw StateFileException.

Implementation

@override
Future<int> loadState(String path) async {
  _checkOpen();
  _contextEpoch++;
  return _queue.run(() async {
    loads++;
    _checkPersistence();
    final failure = failNextLoadState;
    if (failure != null) {
      failNextLoadState = null;
      throw StateFileException('scripted loadState failure', cause: failure);
    }
    try {
      return File(path).readAsStringSync().length ~/ 4;
    } catch (e) {
      throw StateFileException('cannot read $path', cause: e);
    }
  });
}