Future saveAsync()

Asynchronously saves the nodes.json file.

Source

Future saveAsync() async {
  if (_nodesFile != null && provider != null) {
    if (provider is! SerializableNodeProvider) {
      return;
    }

    var count = 0;
    while (_isAsyncSave) {
      await new Future.delayed(const Duration(milliseconds: 5));
      count++;

      if (count == 100) {
        break;
      }
    }

    var encoded = DsJson.encode(
      (provider as SerializableNodeProvider).save(),
      pretty: encodePrettyJson
    );

    _isAsyncSave = true;

    await _nodesFile.writeAsString(encoded);

    _isAsyncSave = false;
  }
}