Skip to content

Commit

Permalink
Deprecate Observable.create
Browse files Browse the repository at this point in the history
Deprecate `Observable.create` and remove related codes.
  • Loading branch information
zsxwing committed Jun 15, 2016
1 parent 4d96d57 commit 9f80cc0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 35 deletions.
16 changes: 1 addition & 15 deletions examples/src/test/scala/examples/RxScalaDemo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,7 @@ class RxScalaDemo extends JUnitSuite {
case _ => throw new IllegalArgumentException
}
}

/**
* This is a bad way of using Observable.create, because even if the consumer unsubscribes,
* all elements are calculated.
*/
@Test def createExampleBad() {
val o = Observable.create[String](observer => {
observer.onNext(calculateElement(0))
observer.onNext(calculateElement(1))
observer.onCompleted()
Subscription {}
})
o.take(1).subscribe(println(_))
}


/**
* This is the good way of doing it: If the consumer unsubscribes, no more elements are
* calculated.
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/rx/lang/scala/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4853,6 +4853,7 @@ object Observable {
* @return
* an Observable that, when an [[rx.lang.scala.Observer]] subscribes to it, will execute the given function.
*/
@deprecated("Use [[Observable.apply]] instead", "0.26.2")
def create[T](f: Observer[T] => Subscription): Observable[T] = {
Observable(
(subscriber: Subscriber[T]) => {
Expand Down
16 changes: 0 additions & 16 deletions src/test/scala/rx/lang/scala/ObservableTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,6 @@ class ObservableTests extends JUnitSuite {
assertEquals(expected, r)
}

@Test
def testCreate() {
var called = false
val o = Observable.create[String](observer => {
observer.onNext("a")
observer.onNext("b")
observer.onNext("c")
observer.onCompleted()
Subscription {
called = true
}
})
assertEquals(List("a", "b", "c"), o.toBlocking.toList)
assertTrue(called)
}

@Test
def testToTraversable() {
val o = Observable.just(1, 2, 3).toTraversable
Expand Down
5 changes: 1 addition & 4 deletions src/test/scala/rx/lang/scala/SubscriptionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ class SubscriptionTests extends JUnitSuite {
@Test
def testIssue85: Unit = {
// https://github.com/ReactiveX/RxScala/issues/85
val xs = Observable.create[Nothing](o => {
val xs = Observable.apply[Nothing](o => {
o.onCompleted()
Subscription {
// do nothing
}
})
val s = xs.subscribe()
assertTrue(s.isUnsubscribed)
Expand Down

0 comments on commit 9f80cc0

Please sign in to comment.