Last active
August 29, 2015 14:06
-
-
Save blmarket/4b9525402529a061be3f to your computer and use it in GitHub Desktop.
Scala implementation of redis subscribe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.redis.RedisClient | |
import rx.lang.scala._ | |
import rx.lang.scala.schedulers._ | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val o = Observable.create(func) | |
o.subscribe(println(_)) | |
o.toBlocking.last // block process to see it works. | |
} | |
def func(ob: Observer[String]): Subscription = { | |
val c = new RedisClient() | |
val worker: Worker = ComputationScheduler().createWorker | |
worker.schedule { // new thread | |
c.subscribe("test_channel")(x => { | |
ob.onNext(x.toString) | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment