Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Stream<T>
  4. take method
take
description

take method

Stream<T>take(
  1. intcount
)

Provides at most the firstcount data events of this stream.

Returns a stream that emits the same events that this stream wouldif listened to at the same time,until either this stream ends or it has emittedcount data events,at which point the returned stream is done.

If this stream produces fewer thancount data events before it's done,so will the returned stream.

Starts listening to this stream when the returned stream is listened toand stops listening when the firstcount data events have been received.

This means that if this is a single-subscription (non-broadcast) streamsit cannot be reused after the returned stream has been listened to.

If this is a broadcast stream, the returned stream is a broadcast stream.In that case, the events are only counted from the timethe returned stream is listened to.

Example:

final stream =    Stream<int>.periodic(const Duration(seconds: 1), (i) => i)        .take(60);stream.forEach(print); // Outputs events: 0, ... 59.

Implementation

Stream<T> take(int count) {  return _TakeStream<T>(this, count);}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. take method
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp