File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
src/main/scala/me/ivovk/cedi Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ Allocator.create[IO]().withListener(new LoggingAllocationListener[IO])
108108
109109You can have multiple dependencies objects and combine them together. In this case, you can either reuse the same
110110` Allocator ` object or create a new one for each dependency object, but wrap their instantiation
111- in ` allocator. allocate { ... }` so that they are shut down in the right order:
111+ in ` allocate { ... } ` so that they are shut down in the right order:
112112
113113Example reusing the same ` Allocator ` object:
114114
@@ -129,7 +129,7 @@ object Dependencies {
129129}
130130
131131class Dependencies (using AllocatorIO ) {
132- val aws = new AwsDependencies (allocator)
132+ val aws = new AwsDependencies
133133
134134 lazy val http4sClient : Client [IO ] = allocate {
135135 EmberClientBuilder .default[IO ].build
@@ -168,11 +168,11 @@ object Dependencies {
168168}
169169
170170class Dependencies (using AllocatorIO ) {
171- lazy val aws = allocator. allocate {
171+ lazy val aws = allocate {
172172 AwsDependencies .create()
173173 }
174174
175- lazy val http4sClient : Client [IO ] = http4sAllocator. allocate {
175+ lazy val http4sClient : Client [IO ] = allocate {
176176 EmberClientBuilder .default[IO ].build
177177 }
178178}
Original file line number Diff line number Diff line change @@ -15,8 +15,10 @@ object Allocator {
1515 dispatcher <- Dispatcher .parallel[F ]
1616 shutdownRef <- Ref .of(Async [F ].unit).toResource
1717 allocator <- {
18- val acquire = Async [F ].delay(new Allocator (dispatcher, shutdownRef, NoOpListener [F ]))
19- val release = (a : Allocator [F ]) => a.shutdownAll
18+ val acquire : F [Allocator [F ]] = Async [F ].delay {
19+ new Allocator (dispatcher, shutdownRef, NoOpListener [F ])
20+ }
21+ val release : Allocator [F ] => F [Unit ] = _.shutdownAll
2022
2123 Resource .make(acquire)(release)
2224 }
@@ -56,7 +58,8 @@ class Allocator[F[_]: Sync] private (
5658 dispatcher.unsafeRunSync(fa)
5759 }
5860
59- def allocate [A : ClassTag ](fa : F [A ]): A = allocate(fa.toResource)
61+ def allocate [A : ClassTag ](fa : F [A ]): A =
62+ allocate(fa.toResource)
6063
6164 def shutdownAll : F [Unit ] =
6265 shutdown.getAndSet(Sync [F ].unit).flatten
Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ import scala.reflect.ClassTag
77object syntax {
88
99 type Allocator [F [_]] = me.ivovk.cedi.Allocator [F ]
10- type AllocatorIO = me.ivovk.cedi.Allocator [IO ]
10+ val Allocator : me.ivovk.cedi.Allocator .type = me.ivovk.cedi.Allocator
11+ type AllocatorIO = me.ivovk.cedi.Allocator [IO ]
1112
1213 def allocate [F [_]: Allocator , A : ClassTag ](fa : F [A ]): A =
1314 Allocator [F ].allocate(fa)
You can’t perform that action at this time.
0 commit comments