Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxScala Schedulers #1187

Closed
headinthebox opened this issue May 12, 2014 · 8 comments
Closed

RxScala Schedulers #1187

headinthebox opened this issue May 12, 2014 · 8 comments

Comments

@headinthebox
Copy link
Contributor

I think it is a mistake to use Unit => Unit instead of () => Unit. Any takers, or I'll fix it later this week.

trait Worker extends Subscription {
  private [scala] val asJavaWorker: rx.Scheduler.Worker

  /**
   * Schedules a cancelable action to be executed in delayTime.
   */
  def schedule(action: Unit => Unit, delayTime: Duration): Subscription =
    this.asJavaWorker.schedule(
      new Action0 {
        override def call(): Unit = action()
      },
      delayTime.length,
      delayTime.unit)

  /**
   * Schedules a cancelable action to be executed immediately.
   */
  def schedule(action: Unit => Unit): Subscription = this.asJavaWorker.schedule(
    new Action0 {
      override def call(): Unit = action()
    }
  )
@zsxwing
Copy link
Member

zsxwing commented May 12, 2014

The original implementation uses (action: => Unit). Do you think which one is better? I prefer (action: => Unit).

@headinthebox
Copy link
Contributor Author

=>Unit would be even better.

@headinthebox
Copy link
Contributor Author

One caveat, to do recursive scheduling we might want to use the same method as in Java; which does not seem to work with =>Unit.

def random(seed: Int): Observable[Double] = {
    Observable(subscriber => {
      val r: Random = new Random(seed)
      val inner = rx.lang.scala.schedulers.NewThreadScheduler().createWorker
      subscriber.add(inner)

      inner.schedule(new Function[Unit, Unit]{
        override def apply(unit: Unit): Unit = {
          val n = r.nextDouble()
          subscriber.onNext(n)
          inner.schedule(apply)
        }
      })
    })
  }

@zsxwing
Copy link
Member

zsxwing commented May 12, 2014

OK. I'll take it and add some examples to test the signature.

@headinthebox
Copy link
Contributor Author

Cool.

zsxwing added a commit to zsxwing/RxJava that referenced this issue May 12, 2014
zsxwing added a commit to zsxwing/RxJava that referenced this issue May 12, 2014
@samuelgruetter
Copy link
Contributor

this is nice :)

benjchristensen added a commit that referenced this issue May 16, 2014
jbripley pushed a commit to jbripley/RxJava that referenced this issue May 17, 2014
@benjchristensen
Copy link
Member

@zsxwing Is this done after merging that PR?

@zsxwing
Copy link
Member

zsxwing commented May 20, 2014

Yes, already fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants