Interval creates an Observable emitting incremental integers infinitely between each given time interval.
(interval Duration, opts ...Option)
| 206 | // Interval creates an Observable emitting incremental integers infinitely between |
| 207 | // each given time interval. |
| 208 | func Interval(interval Duration, opts ...Option) Observable { |
| 209 | option := parseOptions(opts...) |
| 210 | next := option.buildChannel() |
| 211 | ctx := option.buildContext(emptyContext) |
| 212 | |
| 213 | go func() { |
| 214 | i := 0 |
| 215 | for { |
| 216 | select { |
| 217 | case <-time.After(interval.duration()): |
| 218 | if !Of(i).SendContext(ctx, next) { |
| 219 | return |
| 220 | } |
| 221 | i++ |
| 222 | case <-ctx.Done(): |
| 223 | close(next) |
| 224 | return |
| 225 | } |
| 226 | } |
| 227 | }() |
| 228 | return &ObservableImpl{ |
| 229 | iterable: newEventSourceIterable(ctx, next, option.getBackPressureStrategy()), |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Just creates an Observable with the provided items. |
| 234 | func Just(items ...interface{}) func(opts ...Option) Observable { |
searching dependent graphs…