-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package neotypes.monix | ||
|
||
import monix.eval.Task | ||
import monix.execution.Scheduler | ||
import neotypes.Async | ||
|
||
class MonixAsync(implicit s: Scheduler) extends Async[Task] { | ||
|
||
override def async[T](cb: (Either[Throwable, T] => Unit) => Unit): Task[T] = Task.async(cb) | ||
|
||
override def flatMap[T, U](m: Task[T])(f: T => Task[U]): Task[U] = m.flatMap(f) | ||
|
||
override def map[T, U](m: Task[T])(f: T => U): Task[U] = m.map(f) | ||
|
||
override def recoverWith[T, U >: T](m: Task[T])(f: PartialFunction[Throwable, Task[U]]): Task[U] = | ||
m.onErrorRecoverWith(f) | ||
|
||
override def failed[T](e: Throwable): Task[T] = Task.raiseError(e) | ||
} | ||
|
||
object implicits { | ||
implicit def monixAsync(implicit s: Scheduler): Async[Task] = new MonixAsync | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package neotypes.monix | ||
|
||
import monix.eval.Task | ||
import monix.execution.Scheduler.Implicits.global | ||
import neotypes.monix.implicits._ | ||
import neotypes.implicits._ | ||
import neotypes.{BaseIntegrationSpec, BasicSessionSpec} | ||
import org.neo4j.driver.v1.exceptions.ClientException | ||
import org.scalatest.FlatSpec | ||
|
||
import scala.concurrent.duration._ | ||
|
||
class MonixAsyncSpec extends FlatSpec with BaseIntegrationSpec { | ||
it should "work with Task" in { | ||
val s = driver.session().asScala[Task] | ||
|
||
val string = "match (p:Person {name: 'Charlize Theron'}) return p.name".query[String].single(s) | ||
.runSyncUnsafe(5 seconds) | ||
assert(string == "Charlize Theron") | ||
|
||
assertThrows[ClientException] { | ||
"match test return p.name".query[String].single(s).runSyncUnsafe(5 seconds) | ||
} | ||
} | ||
|
||
override val initQuery: String = BasicSessionSpec.INIT_QUERY | ||
} |