-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blockTimer and rename to blockShift #19
Changes from 5 commits
1991a71
5ce3782
6b669e5
33fa207
83fa864
f960e9a
06b72ea
bb3a102
2a60131
6a8f8fc
a76a18c
ca5545e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,44 @@ | ||
package io.chrisdavenport.linebacker | ||
|
||
import cats._ | ||
import cats.implicits._ | ||
import cats.effect.Async | ||
import cats.effect._ | ||
import java.util.concurrent.ExecutorService | ||
import scala.concurrent.ExecutionContext | ||
|
||
trait Linebacker[F[_]] { | ||
|
||
def blockingPool: ExecutionContext | ||
def blockingContext: ExecutionContext | ||
|
||
@deprecated("0.2.0", "Use blockingContext instead.") | ||
private[linebacker] def blockingPool: ExecutionContext = blockingContext | ||
|
||
@deprecated("0.2.0", "Use blockShift instead.") | ||
final private[linebacker] def block[A]( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just because I got trolled, what's the point in only deprecating and just just outright removing when you don't need bincompat for 0.2 yet? |
||
fa: F[A])(implicit F: Async[F], ec: ExecutionContext): F[A] = | ||
blockShift(fa)(F, ec) | ||
|
||
/** | ||
* Attempts to Run the Given `F[A]` on the blocking pool. | ||
* Then shifts back to the given implicit execution context | ||
* after the Async `F[A]` is evaluated. | ||
*/ | ||
final def block[A](fa: F[A])(implicit F: Async[F], ec: ExecutionContext): F[A] = | ||
for { | ||
_ <- Async.shift(blockingPool) | ||
eA <- fa.attempt | ||
_ <- Async.shift(ec) | ||
a <- Applicative[F].pure(eA).rethrow | ||
} yield a | ||
final def blockShift[A](fa: F[A])(implicit F: Async[F], ec: ExecutionContext): F[A] = | ||
F.bracket(Async.shift[F](blockingContext))(_ => fa)(_ => Async.shift[F](ec)) | ||
|
||
/** | ||
* Attempts to Run the Given `F[A]` on the blocking pool. | ||
* Then shifts back to the F for the timer. | ||
*/ | ||
final def blockTimer[A](fa: F[A])(implicit F: Async[F], timer: Timer[F]): F[A] = | ||
F.bracket(Async.shift[F](blockingContext))(_ => fa)(_ => timer.shift) | ||
} | ||
|
||
object Linebacker { | ||
def apply[F[_]](implicit ev: Linebacker[F]): Linebacker[F] = ev | ||
|
||
def fromExecutorService[F[_]](es: ExecutorService): Linebacker[F] = new Linebacker[F] { | ||
def blockingPool = ExecutionContext.fromExecutorService(es) | ||
def blockingContext = ExecutionContext.fromExecutorService(es) | ||
} | ||
def fromExecutionContext[F[_]](ec: ExecutionContext): Linebacker[F] = new Linebacker[F] { | ||
def blockingPool = ec | ||
def blockingContext = ec | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package io.chrisdavenport.linebacker | ||
|
||
import cats._ | ||
import cats.effect.Async | ||
import cats.implicits._ | ||
import scala.concurrent.ExecutionContext | ||
|
@@ -23,11 +22,8 @@ trait Quarterback[F[_], K] { | |
def fleaFlicker[A](fa: F[A], initial: K, end: K)(implicit F: Async[F]): F[A] = | ||
for { | ||
iEC <- select(initial) | ||
_ <- Async.shift(iEC) | ||
aE <- fa.attempt | ||
eEC <- select(end) | ||
_ <- Async.shift(eEC) | ||
a <- Applicative[F].pure(aE).rethrow | ||
endEC <- select(end) | ||
a <- Async[F].bracket(Async.shift[F](iEC))(_ => fa)(_ => Async.shift(endEC)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this is like the third time I see this. I think this is pointing to the need of either some package object or object definition of something like: private[linebacker] final def dualShift[F[_], A](initialEc: ExecutionContext, endEc: ExecutionContext, action: F[A])(implicit F: Async[F]) =
F.bracket(Async.shift[F](initialEc))(_ => fa)(_ => Async.shift[F](encEc)) Then just calling |
||
} yield a | ||
} | ||
object Quarterback { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=1.1.5 | ||
sbt.version=1.1.6 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version in ThisBuild := "0.1.1-SNAPSHOT" | ||
version in ThisBuild := "0.2.0-SNAPSHOT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this at all when RC2 isn't compatible with cats 0.10?