test("watchOrders") {
var result = List.empty[Order]
val stream = client.watchOrders()
val promise = Promise[Assertion]()
stream.fold(List.empty[Order]) {
case (acc, Some(elem)) =>
val result = elem :: acc
println("result size: " + result.size)
if (result.size == 4) promise.success({
assert(validateTheOrders(result))
})
result
}
promise.future
}
validateTheOrders(result)
is passed, the test will pass and terminate as expected
result size
printed in console will be:result size: 1
result size: 2
result size: 3
result size: 4
result size: 4
result size: 4
result size: 4
...
@Voltir I just make it work inspired with the eventually
method from haoyi's utest. Now I'm still using scalatest's SyncTestSuit, and the code is like:
private def waitUntil[T](stream: Rx[T])(cond: T => Boolean, maxWait: Duration): T = {
val promise = Promise[T]()
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() => {
val list = stream.now
if (cond(list)) {
promise.success(list)
}
}, 0L, 100L, TimeUnit.MILLISECONDS)
Await.result(promise.future, maxWait)
}
test("watchOrders") {
val stream = client.watchOrders()
val listRx: Rx[List[Order]] = stream.fold(List.empty[Order]) {
case (acc, Some(elem)) => elem :: acc
case (acc, _) => acc
}
val list = waitUntil(listRx)(_.size >= 4, 10.seconds)
assert(validateTheOrders(list))
}
It's working great now
implicit val ctx = Ctx.Owner.save()
in my class? I have seen that somewhere....save()
lacks documentation.
import rx._
but my code says not found: value Obs
in this code piece for providing the implicit conversion.
"scalarx" % "0.2.8"
, but latest is "0.4.0"
implicit def rxFrag[T](r: Rx[T])(implicit dataCtx: Ctx.Data, ev: T => Frag): Frag = {
import Ctx.Owner.Unsafe._
def rSafe: dom.Node = span(r()).render
var last = rSafe
r.triggerLater {
val newLast = rSafe
js.Dynamic.global.last = last
last.parentNode.replaceChild(newLast, last)
last = newLast
}
last
}
implicit Ctx.Data
...
@lihaoyi and other contributors, thank you for an excellent library. I'm more productive and concise than every I was with scalajs-react and scala.binding.
@lihaoyi will you be at ScalaDays Lausanne in a few weeks? Any one else who uses scala.rx going to be there? It would be great to meet up, discuss experiences and share a drink!! If you are interested, please post!!!
Rx {
for (row <- rows()) yield tr(...)
}
Ctx.Owner
and Ctx.Data
which I suspect are somehow related. I know there are some open tickets related to documentation on that stuff. I’d be more than happy to translate a discussion here into a PR for the docs.