|
1 | 1 | package io.catbird.util.effect |
2 | 2 |
|
3 | 3 | import cats.effect.Clock |
| 4 | +import cats.effect.kernel.{ MonadCancel, Outcome, Sync } |
4 | 5 | import com.twitter.util.{ Future, Monitor } |
5 | 6 | import io.catbird.util.{ Rerunnable, RerunnableMonadError } |
6 | 7 |
|
7 | 8 | import java.lang.Throwable |
8 | 9 | import java.util.concurrent.TimeUnit |
9 | 10 | import java.lang.System |
10 | | -import cats.effect.kernel.{ MonadCancel, Outcome, Sync } |
11 | 11 |
|
12 | 12 | import scala.Unit |
13 | 13 | import scala.concurrent.duration.FiniteDuration |
@@ -50,64 +50,4 @@ trait RerunnableInstances { |
50 | 50 | } |
51 | 51 | } |
52 | 52 | } |
53 | | - |
54 | | - /* |
55 | | - implicit final val rerunnableEffectInstance: Effect[Rerunnable] = |
56 | | - new RerunnableMonadError { // with Effect[Rerunnable] { |
57 | | - final def suspend[A](thunk: => Rerunnable[A]): Rerunnable[A] = Rerunnable.suspend[A](thunk) |
58 | | -
|
59 | | - //override final def delay[A](thunk: => A): Rerunnable[A] = Rerunnable[A](thunk) |
60 | | -
|
61 | | - final def async[A](k: (Either[Throwable, A] => Unit) => Unit): Rerunnable[A] = |
62 | | - new Rerunnable[A] { |
63 | | - final def run: Future[A] = { |
64 | | - val promise = new Promise[A] |
65 | | -
|
66 | | - k { e => |
67 | | - if (promise.isDefined) () |
68 | | - else |
69 | | - e match { |
70 | | - case Right(a) => promise.setValue(a) |
71 | | - case Left(err) => promise.setException(err) |
72 | | - } |
73 | | - } |
74 | | -
|
75 | | - promise |
76 | | - } |
77 | | - } |
78 | | -
|
79 | | - final def asyncF[A](k: (Either[Throwable, A] => Unit) => Rerunnable[Unit]): Rerunnable[A] = |
80 | | - new Rerunnable[A] { |
81 | | - final def run: Future[A] = { |
82 | | - val promise = new Promise[A] |
83 | | -
|
84 | | - val rerunnable = k { e => |
85 | | - if (promise.isDefined) () |
86 | | - else |
87 | | - e match { |
88 | | - case Right(a) => promise.setValue(a) |
89 | | - case Left(err) => promise.setException(err) |
90 | | - } |
91 | | - } |
92 | | -
|
93 | | - rerunnable.run.flatMap(_ => promise) |
94 | | - } |
95 | | - } |
96 | | -
|
97 | | -// final def runAsync[A](fa: Rerunnable[A])(cb: Either[Throwable, A] => IO[Unit]): SyncIO[Unit] = |
98 | | -// rerunnableToIO[A](fa).runAsync(cb) |
99 | | -
|
100 | | - final def bracketCase[A, B](acquire: Rerunnable[A])(use: A => Rerunnable[B])( |
101 | | - release: (A, ExitCase) => Rerunnable[Unit] |
102 | | - ): Rerunnable[B] = new Rerunnable[B] { |
103 | | - final def run: Future[B] = |
104 | | - acquire.run.flatMap { a => |
105 | | - val future = use(a).run |
106 | | - future.transform(result => |
107 | | - release(a, tryToExitCase(result)).run.handle(Monitor.catcher).flatMap(_ => future) |
108 | | - ) |
109 | | - } |
110 | | - } |
111 | | - } |
112 | | - */ |
113 | 53 | } |
0 commit comments