Skip to content

,System.Func{System.IObservable{--1}})} ,System.IObservable{--1},System.Func{--1,System.IObservable{--2}})} ,System.IObservable{--1})} ,System.Int32)} ,System.Int32,System.Int32)} ,System.TimeSpan)} ,System.TimeSpan,System.Reactive.Concurrency.IScheduler)} ,System.TimeSpan,System.TimeSpan)} ,System.TimeSpan,System.TimeSpan,System.Reactive.Concurrency.IScheduler)} ,System.TimeSpan,System.Int32)} ,System.TimeSpan,System.Int32,System.Reactive.Concurrency.IScheduler)}

Observable.Buffer(IObservable, Func>) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<IList<TSource>> Buffer<TSource, TBufferClosing>(this IObservable<TSource> source, Func<IObservable<TBufferClosing>> bufferClosingSelector)
  • 2. public static IObservable<IList<TSource>> Buffer<TSource, TBufferOpening, TBufferClosing>(this IObservable<TSource> source, IObservable<TBufferOpening> bufferOpenings, Func<TBufferOpening, IObservable<TBufferClosing>> bufferClosingSelector)
  • 3. public static IObservable<IList<TSource>> Buffer<TSource, TBufferBoundary>(this IObservable<TSource> source, IObservable<TBufferBoundary> bufferBoundaries)
  • 4. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count)
  • 5. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count, int skip)
  • 6. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan)
  • 7. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, IScheduler scheduler)
  • 8. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)
  • 9. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift, IScheduler scheduler)
  • 10. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count)
  • 11. public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count, IScheduler scheduler)

1. Overload

public static IObservable<IList<TSource>> Buffer<TSource, TBufferClosing>(this IObservable<TSource> source, Func<IObservable<TBufferClosing>> bufferClosingSelector)

Summary: Projects each element of an observable sequence into consecutive non-overlapping buffers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.
TBufferClosingThe type of the elements in the sequences indicating buffer closing events.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
bufferClosingSelectorFunc>A function invoked to define the boundaries of the produced buffers. A new buffer is started when the previous one is closed.

Returns: IObservable> -- An observable sequence of buffers.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or bufferClosingSelector is null.

2. Overload

public static IObservable<IList<TSource>> Buffer<TSource, TBufferOpening, TBufferClosing>(this IObservable<TSource> source, IObservable<TBufferOpening> bufferOpenings, Func<TBufferOpening, IObservable<TBufferClosing>> bufferClosingSelector)

Summary: Projects each element of an observable sequence into zero or more buffers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.
TBufferOpeningThe type of the elements in the sequence indicating buffer opening events, also passed to the closing selector to obtain a sequence of buffer closing events.
TBufferClosingThe type of the elements in the sequences indicating buffer closing events.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
bufferOpeningsIObservableObservable sequence whose elements denote the creation of new buffers.
bufferClosingSelectorFunc>A function invoked to define the closing of each produced buffer.

Returns: IObservable> -- An observable sequence of buffers.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or bufferOpenings or bufferClosingSelector is null.

3. Overload

public static IObservable<IList<TSource>> Buffer<TSource, TBufferBoundary>(this IObservable<TSource> source, IObservable<TBufferBoundary> bufferBoundaries)

Summary: Projects each element of an observable sequence into consecutive non-overlapping buffers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.
TBufferBoundaryThe type of the elements in the sequences indicating buffer boundary events.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
bufferBoundariesIObservableSequence of buffer boundary markers. The current buffer is closed and a new buffer is opened upon receiving a boundary marker.

Returns: IObservable> -- An observable sequence of buffers.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or bufferBoundaries is null.

4. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count)

Summary: Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on element count information.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
countintLength of each buffer.

Returns: IObservable> -- An observable sequence of buffers.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptioncount is less than or equal to zero.

5. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count, int skip)

Summary: Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
countintLength of each buffer.
skipintNumber of elements to skip between creation of consecutive buffers.

Returns: IObservable> -- An observable sequence of buffers.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptioncount or skip is less than or equal to zero.

6. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan)

Summary: Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on timing information.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanLength of each buffer.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers as fast as it can. Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptiontimeSpan is less than TimeSpan.Zero.

7. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, IScheduler scheduler)

Summary: Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on timing information, using the specified scheduler to run timers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanLength of each buffer.
scheduler[IScheduler](#Scheduler to run buffering timers on.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers as fast as it can. Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptiontimeSpan is less than TimeSpan.Zero.

8. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift)

Summary: Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanLength of each buffer.
timeShiftTimeSpanInterval between creation of consecutive buffers.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers with minimum duration length. However, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer may not execute immediately, despite the TimeSpan.Zero due time.

Specifying a TimeSpan.Zero value for timeShift is not recommended but supported, causing the scheduler to create buffers as fast as it can. However, this doesn't mean all buffers will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler, where the action to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptiontimeSpan or timeSpan is less than TimeSpan.Zero.

9. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, TimeSpan timeShift, IScheduler scheduler)

Summary: Projects each element of an observable sequence into zero or more buffers which are produced based on timing information, using the specified scheduler to run timers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanLength of each buffer.
timeShiftTimeSpanInterval between creation of consecutive buffers.
scheduler[IScheduler](#Scheduler to run buffering timers on.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers with minimum duration length. However, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer may not execute immediately, despite the TimeSpan.Zero due time.

Specifying a TimeSpan.Zero value for timeShift is not recommended but supported, causing the scheduler to create buffers as fast as it can. However, this doesn't mean all buffers will start at the beginning of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler, where the action to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptiontimeSpan or timeSpan is less than TimeSpan.Zero.

10. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count)

Summary: Projects each element of an observable sequence into a buffer that's sent out when either it's full or a given amount of time has elapsed. A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanMaximum time length of a window.
countintMaximum element count of a window.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers as fast as it can. Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.
System.ArgumentOutOfRangeExceptiontimeSpan is less than TimeSpan.Zero. -or- count is less than or equal to zero.

11. Overload

public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, TimeSpan timeSpan, int count, IScheduler scheduler)

Summary: Projects each element of an observable sequence into a buffer that's sent out when either it's full or a given amount of time has elapsed, using the specified scheduler to run timers. A useful real-world analogy of this overload is the behavior of a ferry leaving the dock when all seats are taken, or at the scheduled time of departure, whichever event occurs first.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence, and in the lists in the result sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to produce buffers over.
timeSpanTimeSpanMaximum time length of a buffer.
countintMaximum element count of a buffer.
scheduler[IScheduler](#Scheduler to run buffering timers on.

Returns: IObservable> -- An observable sequence of buffers.

Remarks

Specifying a TimeSpan.Zero value for timeSpan is not recommended but supported, causing the scheduler to create buffers as fast as it can. Because all source sequence elements end up in one of the buffers, some buffers won't have a zero time span. This is a side-effect of the asynchrony introduced by the scheduler, where the action to close the current buffer and to create a new buffer may not execute immediately, despite the TimeSpan.Zero due time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.
System.ArgumentOutOfRangeExceptiontimeSpan is less than TimeSpan.Zero. -or- count is less than or equal to zero.