Skip to content

Commit 1844aa4

Browse files
authored
Add methods to create successful & failed forks (#98)
1 parent 8dee925 commit 1844aa4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/src/main/scala/ox/fork.scala

+7
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ trait Fork[T]:
217217
case e: InterruptedException => Left(e)
218218
case NonFatal(e) => Left(e)
219219

220+
object Fork:
221+
/** A dummy pretending to represent a fork which successfully completed with the given value. */
222+
def successful[T](value: T): Fork[T] = () => value
223+
224+
/** A dummy pretending to represent a fork which failed with the given exception. */
225+
def failed[T](e: Throwable): Fork[T] = () => throw e
226+
220227
/** A fork started using [[forkCancellable]], backed by a (virtual) thread. */
221228
trait CancellableFork[T] extends Fork[T]:
222229
/** Interrupts the fork, and blocks until it completes with a result. */

0 commit comments

Comments
 (0)