ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.37k stars 270 forks source link

illegal_async_generator_return_type when using async* on a method that returns ValueStream #692

Closed Prn-Ice closed 2 years ago

Prn-Ice commented 2 years ago

Hi, this is probably just poor understanding on my part but i'm trying to do this

ValueStream<WalletsResponse> get wallets async* {
    final initial = await _walletCache.get(IWalletRepository.cacheKey);

    yield* _walletCache
        .on<CacheEntryUpdatedEvent<WalletsResponse>>()
        .map((event) => event.newEntry.value as WalletsResponse)
        .shareValueSeeded(initial ?? WalletsResponse());
  }

But I keep getting the error

Functions marked 'async*' must have a return type that is a supertype of 'Stream<T>' for some type 'T'.
Try fixing the return type of the function, or removing the modifier 'async*' from the function body.dart[illegal_async_generator_return_type](https://dart.dev/diagnostics/illegal_async_generator_return_type)

Since ValueStream implements Stream, I am a little surprised seeing this.

hoc081098 commented 2 years ago

Because that is dart language spec.

ValueStream<WalletsResponse> get wallets {
    return Rx.fromCallable(() => _walletCache.get(IWalletRepository.cacheKey))
       .exhaustMap((initial) =>
          _walletCache
            .on<CacheEntryUpdatedEvent<WalletsResponse>>()
            .map((event) => event.newEntry.value as WalletsResponse)
            .startWith(initial)
       )
       .shareValueSeeded(WalletsResponse());
  }

Sent from my 2201117TG using FastHub

Prn-Ice commented 2 years ago

Thanks.