Skip to content

Commit

Permalink
avoid org.atnos.eff.all in core/main
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jul 26, 2021
1 parent d065cc2 commit d1d6900
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
13 changes: 6 additions & 7 deletions shared/src/main/scala/org/atnos/eff/FutureEffect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import java.util.concurrent.TimeoutException

import cats._
import cats.syntax.all._
import org.atnos.eff.all._
import org.atnos.eff.concurrent.Scheduler

import scala.concurrent.duration.FiniteDuration
Expand Down Expand Up @@ -75,25 +74,25 @@ trait FutureTypes {
trait FutureCreation extends FutureTypes {

final def fromFutureWithExecutors[R :_future, A](c: (Scheduler, ExecutionContext) => Future[A], timeout: Option[FiniteDuration] = None): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture(c, timeout))
Eff.send[TimedFuture, R, A](TimedFuture(c, timeout))

final def fromFuture[R :_future, A](c: => Future[A], timeout: Option[FiniteDuration] = None): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture((_, _) => c, timeout))
Eff.send[TimedFuture, R, A](TimedFuture((_, _) => c, timeout))

final def futureFail[R :_future, A](t: Throwable): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture((_, _) => Future.failed(t)))
Eff.send[TimedFuture, R, A](TimedFuture((_, _) => Future.failed(t)))

final def futureFromEither[R :_future, A](e: Throwable Either A): Eff[R, A] =
e.fold(futureFail[R, A], Eff.pure[R, A])

final def futureDelay[R :_future, A](a: => A, timeout: Option[FiniteDuration] = None): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture((_, ec) => Future(a)(ec), timeout))
Eff.send[TimedFuture, R, A](TimedFuture((_, ec) => Future(a)(ec), timeout))

final def futureFork[R :_future, A](a: => A, ec: ExecutionContext, timeout: Option[FiniteDuration] = None): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture((_, _) => Future(a)(ec), timeout))
Eff.send[TimedFuture, R, A](TimedFuture((_, _) => Future(a)(ec), timeout))

final def futureDefer[R :_future, A](a: => Future[A], timeout: Option[FiniteDuration] = None): Eff[R, A] =
send[TimedFuture, R, A](TimedFuture((_, _) => a, timeout))
Eff.send[TimedFuture, R, A](TimedFuture((_, _) => a, timeout))

def retryUntil[R :_future, A](e: Eff[R, A], condition: A => Boolean, durations: List[FiniteDuration]): Eff[R, A] =
Eff.retryUntil(e, condition, durations, d => waitFor(d))
Expand Down
7 changes: 3 additions & 4 deletions shared/src/main/scala/org/atnos/eff/ValidateEffect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.atnos.eff

import cats._, data._
import cats.syntax.all._
import org.atnos.eff.all._
import Interpret._

/**
Expand Down Expand Up @@ -38,15 +37,15 @@ trait ValidateCreation {

/** create a failed value */
def wrong[R, E](e: E)(implicit m: Validate[E, *] |= R): Eff[R, Unit] =
send[Validate[E, *], R, Unit](Wrong(e))
Eff.send[Validate[E, *], R, Unit](Wrong(e))

/** create a correct value */
def correct[R, E, A](a: A)(implicit m: Validate[E, *] |= R): Eff[R, A] =
send[Validate[E, *], R, Unit](Correct[E]()) >> Eff.EffMonad[R].pure(a)
Eff.send[Validate[E, *], R, Unit](Correct[E]()) >> Eff.EffMonad[R].pure(a)

/** create a pure warning */
def warning[R, E](e: E)(implicit m: Validate[E, *] |= R): Eff[R, Unit] =
send[Validate[E, *], R, Unit](Warning[E](e))
Eff.send[Validate[E, *], R, Unit](Warning[E](e))

/** create a correct value with warning */
def warning[R, E, A](a: A, e: E)(implicit m: Validate[E, *] |= R): Eff[R, A] =
Expand Down

0 comments on commit d1d6900

Please sign in to comment.