飞镖!未来的经营者

时间:2020-11-01 14:21:40

标签: dart

!之后的_cachedValueFuture运算符是什么?

  Future<T> fetch(Future<T> Function() callback) async {
    if (_cachedStreamSplitter != null) {
      throw StateError('Previously used to cache via `fetchStream`');
    }
    if (_cachedValueFuture == null) {
      _cachedValueFuture = callback();
      await _cachedValueFuture;
      _startStaleTimer();
    }
    return _cachedValueFuture!;
  }

1 个答案:

答案 0 :(得分:2)

在下一版本中,"(not-)null assertion operator"成为Dart的一部分,具有Null安全功能。

_cachedValueFuture变量的类型为Future<T>?,表示将来或为空。如果值是!,则null运算符将抛出,因此,_cachedValueFuture!的类型是Future<T>,这是该函数所需的返回类型。