-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate ZRunnable, fix interruption handling in the measurementHandle…
…Interruption, add provideSomeEnvironment and provideEnvironment to the ZAkkaFlow and ZAkkaSource
- Loading branch information
Showing
7 changed files
with
101 additions
and
193 deletions.
There are no files selected for viewing
78 changes: 0 additions & 78 deletions
78
chopsticks-fp/src/main/scala/dev/chopsticks/fp/ZManageable.scala
This file was deleted.
Oops, something went wrong.
143 changes: 57 additions & 86 deletions
143
chopsticks-fp/src/main/scala/dev/chopsticks/fp/ZRunnable.scala
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 |
---|---|---|
@@ -1,86 +1,57 @@ | ||
//package dev.chopsticks.fp | ||
// | ||
//import zio.{Scope, URIO, URLayer, ZEnvironment, ZIO, ZLayer} | ||
// | ||
//final class ZRunnable1[A, R, E, V](fn: A => ZIO[R with Scope, E, V]) { | ||
// def toLayer[S: zio.Tag](serviceFactory: (A => ZIO[Any, E, V]) => S): URLayer[R, S] = { | ||
// val io: URIO[R with Scope, S] = ZIO | ||
// .environmentWith[R with Scope]((env: ZEnvironment[R with Scope]) => { | ||
// val newFn = (arg: A) => fn(arg).provideEnvironment(env) | ||
// serviceFactory(newFn) | ||
// }) | ||
// val res: ZLayer[R with Scope, E, S] = ZLayer.scoped(io) | ||
// res | ||
// } | ||
// | ||
// def toZIO: ZIO[R, E, A => ZIO[Any, E, V]] = { | ||
// ZIO | ||
// .environmentWith[R](env => { | ||
// (arg: A) => fn(arg).provideEnvironment(env) | ||
// }) | ||
// } | ||
//} | ||
// | ||
////final class ZRunnable2[A1, A2, R, E, V](fn: (A1, A2) => ZIO[R, E, V]) { | ||
//// def toLayer[S: zio.Tag](serviceFactory: ((A1, A2) => ZIO[Any, E, V]) => S): URLayer[R, Has[S]] = { | ||
//// ZManaged | ||
//// .access[R](env => { | ||
//// val newFn = (arg1: A1, arg2: A2) => fn(arg1, arg2).provide(env) | ||
//// serviceFactory(newFn) | ||
//// }) | ||
//// .toLayer | ||
//// } | ||
//// | ||
//// def toZIO: ZIO[R, E, (A1, A2) => ZIO[Any, E, V]] = { | ||
//// ZIO | ||
//// .access[R](env => { | ||
//// (arg1: A1, arg2: A2) => fn(arg1, arg2).provide(env) | ||
//// }) | ||
//// } | ||
////} | ||
//// | ||
////final class ZRunnable3[A1, A2, A3, R, E, V](fn: (A1, A2, A3) => ZIO[R, E, V]) { | ||
//// def toLayer[S: zio.Tag](serviceFactory: ((A1, A2, A3) => ZIO[Any, E, V]) => S): URLayer[R, Has[S]] = { | ||
//// ZManaged | ||
//// .access[R](env => { | ||
//// val newFn = (arg1: A1, arg2: A2, arg3: A3) => fn(arg1, arg2, arg3).provide(env) | ||
//// serviceFactory(newFn) | ||
//// }) | ||
//// .toLayer | ||
//// } | ||
//// | ||
//// def toZIO: ZIO[R, E, (A1, A2, A3) => ZIO[Any, E, V]] = { | ||
//// ZIO | ||
//// .access[R](env => { | ||
//// (arg1: A1, arg2: A2, arg3: A3) => fn(arg1, arg2, arg3).provide(env) | ||
//// }) | ||
//// } | ||
////} | ||
//// | ||
////final class ZRunnable4[A1, A2, A3, A4, R, E, V](fn: (A1, A2, A3, A4) => ZIO[R, E, V]) { | ||
//// def toLayer[S: zio.Tag](serviceFactory: ((A1, A2, A3, A4) => ZIO[Any, E, V]) => S): URLayer[R, Has[S]] = { | ||
//// ZManaged | ||
//// .access[R](env => { | ||
//// val newFn = (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => fn(arg1, arg2, arg3, arg4).provide(env) | ||
//// serviceFactory(newFn) | ||
//// }) | ||
//// .toLayer | ||
//// } | ||
//// | ||
//// def toZIO: ZIO[R, E, (A1, A2, A3, A4) => ZIO[Any, E, V]] = { | ||
//// ZIO | ||
//// .access[R](env => { | ||
//// (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => fn(arg1, arg2, arg3, arg4).provide(env) | ||
//// }) | ||
//// } | ||
////} | ||
//// | ||
////object ZRunnable { | ||
//// def apply[A, R, E, V](fn: A => ZIO[R, E, V]): ZRunnable1[A, R, E, V] = new ZRunnable1[A, R, E, V](fn) | ||
//// def apply[A1, A2, R, E, V](fn: (A1, A2) => ZIO[R, E, V]): ZRunnable2[A1, A2, R, E, V] = | ||
//// new ZRunnable2[A1, A2, R, E, V](fn) | ||
//// def apply[A1, A2, A3, R, E, V](fn: (A1, A2, A3) => ZIO[R, E, V]): ZRunnable3[A1, A2, A3, R, E, V] = | ||
//// new ZRunnable3[A1, A2, A3, R, E, V](fn) | ||
//// def apply[A1, A2, A3, A4, R, E, V](fn: (A1, A2, A3, A4) => ZIO[R, E, V]): ZRunnable4[A1, A2, A3, A4, R, E, V] = | ||
//// new ZRunnable4[A1, A2, A3, A4, R, E, V](fn) | ||
////} | ||
package dev.chopsticks.fp | ||
|
||
import zio.{Scope, URIO, URLayer, ZEnvironment, ZIO, ZLayer} | ||
|
||
final class ZRunnable1[A, R, E, V](fn: A => ZIO[R with Scope, E, V]) { | ||
def toLayer[S: zio.Tag](serviceFactory: (A => ZIO[Any, E, V]) => S): URLayer[R, S] = { | ||
val io: URIO[R with Scope, S] = ZIO | ||
.environmentWith[R with Scope]((env: ZEnvironment[R with Scope]) => { | ||
val newFn = (arg: A) => fn(arg).provideEnvironment(env) | ||
serviceFactory(newFn) | ||
}) | ||
ZLayer.scoped[R](io) | ||
} | ||
} | ||
|
||
final class ZRunnable2[A1, A2, R, E, V](fn: (A1, A2) => ZIO[R, E, V]) { | ||
def toLayer[S: zio.Tag](serviceFactory: ((A1, A2) => ZIO[Any, E, V]) => S): URLayer[R, S] = { | ||
val io = ZIO | ||
.environmentWith[R with Scope](env => { | ||
val newFn = (arg1: A1, arg2: A2) => fn(arg1, arg2).provideEnvironment(env) | ||
serviceFactory(newFn) | ||
}) | ||
ZLayer.scoped[R](io) | ||
} | ||
} | ||
|
||
final class ZRunnable3[A1, A2, A3, R, E, V](fn: (A1, A2, A3) => ZIO[R, E, V]) { | ||
def toLayer[S: zio.Tag](serviceFactory: ((A1, A2, A3) => ZIO[Any, E, V]) => S): URLayer[R, S] = { | ||
val io = ZIO | ||
.environmentWith[R with Scope](env => { | ||
val newFn = (arg1: A1, arg2: A2, arg3: A3) => fn(arg1, arg2, arg3).provideEnvironment(env) | ||
serviceFactory(newFn) | ||
}) | ||
ZLayer.scoped[R](io) | ||
} | ||
} | ||
|
||
final class ZRunnable4[A1, A2, A3, A4, R, E, V](fn: (A1, A2, A3, A4) => ZIO[R, E, V]) { | ||
def toLayer[S: zio.Tag](serviceFactory: ((A1, A2, A3, A4) => ZIO[Any, E, V]) => S): URLayer[R, S] = { | ||
val io = ZIO | ||
.environmentWith[R](env => { | ||
val newFn = (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => fn(arg1, arg2, arg3, arg4).provideEnvironment(env) | ||
serviceFactory(newFn) | ||
}) | ||
ZLayer.scoped[R](io) | ||
} | ||
} | ||
|
||
object ZRunnable { | ||
def apply[A, R, E, V](fn: A => ZIO[R, E, V]): ZRunnable1[A, R, E, V] = new ZRunnable1[A, R, E, V](fn) | ||
def apply[A1, A2, R, E, V](fn: (A1, A2) => ZIO[R, E, V]): ZRunnable2[A1, A2, R, E, V] = | ||
new ZRunnable2[A1, A2, R, E, V](fn) | ||
def apply[A1, A2, A3, R, E, V](fn: (A1, A2, A3) => ZIO[R, E, V]): ZRunnable3[A1, A2, A3, R, E, V] = | ||
new ZRunnable3[A1, A2, A3, R, E, V](fn) | ||
def apply[A1, A2, A3, A4, R, E, V](fn: (A1, A2, A3, A4) => ZIO[R, E, V]): ZRunnable4[A1, A2, A3, A4, R, E, V] = | ||
new ZRunnable4[A1, A2, A3, A4, R, E, V](fn) | ||
} |
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
ThisBuild / version := "3.13.0-SNAPSHOT" | ||
ThisBuild / version := "4.0.0-SNAPSHOT" |