Skip to content

Commit 27a7871

Browse files
committed
Refine time operator
1 parent 49fc114 commit 27a7871

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ In this example, we create a pool of 32 goroutines that consume items concurrent
277277
* [Range](doc/range.md) — create an Observable that emits a range of sequential integers
278278
* [Repeat](doc/repeat.md) — create an Observable that emits a particular item or sequence of items repeatedly
279279
* [Start](doc/start.md) — create an Observable that emits the return value of a function
280-
* [Timer](doc/timer.md) — create an Observable that emits a single item after a given delay
280+
* [Timer](doc/timer.md) — create an Observable that completes after a specified delay
281281

282282
### Transforming Observables
283283
* [Buffer](doc/buffer.md) — periodically gather items from an Observable into bundles and emit these bundles rather than emitting the items one at a time

doc/timer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Create an Observable that emits a single item after a given delay.
5+
Create an Observable that completes after a specified delay.
66

77
![](http://reactivex.io/documentation/operators/images/timer.png)
88

factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func Thrown(err error) Observable {
336336
}
337337
}
338338

339-
// Timer returns an Observable that emits an empty structure after a specified delay, and then completes.
339+
// Timer returns an Observable that completes after a specified delay.
340340
func Timer(d Duration, opts ...Option) Observable {
341341
option := parseOptions(opts...)
342342
next := make(chan Item, 1)
@@ -348,7 +348,7 @@ func Timer(d Duration, opts ...Option) Observable {
348348
case <-ctx.Done():
349349
return
350350
case <-time.After(d.duration()):
351-
next <- Of(struct{}{})
351+
return
352352
}
353353
}()
354354
return &ObservableImpl{

factory_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,11 @@ func Test_Thrown(t *testing.T) {
385385

386386
func Test_Timer(t *testing.T) {
387387
obs := Timer(WithDuration(time.Nanosecond))
388-
Assert(context.Background(), t, obs, IsNotEmpty())
388+
select {
389+
case <-time.Tick(time.Second):
390+
assert.FailNow(t, "observable not closed")
391+
case <-obs.Observe():
392+
}
389393
}
390394

391395
func Test_Timer_Empty(t *testing.T) {
@@ -395,5 +399,9 @@ func Test_Timer_Empty(t *testing.T) {
395399
time.Sleep(50 * time.Millisecond)
396400
cancel()
397401
}()
398-
Assert(context.Background(), t, obs, IsEmpty())
402+
select {
403+
case <-time.Tick(time.Second):
404+
assert.FailNow(t, "observable not closed")
405+
case <-obs.Observe():
406+
}
399407
}

0 commit comments

Comments
 (0)