Skip to content

Commit

Permalink
use initWith where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fwbrasil committed Jan 20, 2025
1 parent 2f07f80 commit fa19dd5
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion kyo-cache/shared/src/main/scala/kyo/Cache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Cache(private[kyo] val store: Store):
f: A => B < S
)(using Frame): A => B < (Async & S) =
(v: A) =>
Promise.init[Throwable, B].map { p =>
Promise.initWith[Throwable, B] { p =>
val key = (this, v)
IO[B, Async & S] {
val p2 = store.get(key, _ => p.asInstanceOf[Promise[Nothing, Any]])
Expand Down
4 changes: 2 additions & 2 deletions kyo-core/shared/src/main/scala/kyo/Hub.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Hub[A] private[kyo] (
closed.map {
case true => fail
case false =>
Channel.init[A](bufferSize).map { child =>
Channel.initWith[A](bufferSize) { child =>
IO {
discard(listeners.add(child))
closed.map {
Expand Down Expand Up @@ -165,7 +165,7 @@ object Hub:
* The result of applying the function
*/
def initWith[A](capacity: Int)[B, S](f: Hub[A] => B < S)(using Frame): B < (S & IO) =
Channel.init[A](capacity).map { ch =>
Channel.initWith[A](capacity) { ch =>
IO {
val listeners = new CopyOnWriteArraySet[Channel[A]]
Async.run {
Expand Down
4 changes: 2 additions & 2 deletions kyo-core/shared/src/main/scala/kyo/Resource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ object Resource:
* The result of the effect wrapped in Async and S effects.
*/
def run[A, S](closeParallelism: Int)(v: A < (Resource & S))(using frame: Frame): A < (Async & S) =
Queue.Unbounded.init[Unit < (Async & Abort[Throwable])](Access.MultiProducerSingleConsumer).map { q =>
Promise.init[Nothing, Unit].map { p =>
Queue.Unbounded.initWith[Unit < (Async & Abort[Throwable])](Access.MultiProducerSingleConsumer) { q =>
Promise.initWith[Nothing, Unit] { p =>
val finalizer = Finalizer(frame, q)
def close: Unit < IO =
q.close.map {
Expand Down
2 changes: 1 addition & 1 deletion kyo-stm/shared/src/main/scala/kyo/TTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ object TTable:
table <- TTable.init[Fields]
indexes <-
Kyo.foreach(indexFields.toSeq) { field =>
TMap.init[Any, Set[Int]].map(field -> _)
TMap.initWith[Any, Set[Int]](field -> _)
}
yield new Indexed(table, indexes.toMap)(using fields)
end Indexed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class HttpClientKyoBackend private (
) = pipe

override protected def createSimpleQueue[A] =
Channel.init[A](Int.MaxValue).map(new KyoSimpleQueue[A](_))
Channel.initWith[A](Int.MaxValue)(new KyoSimpleQueue[A](_))

override protected def createSequencer =
Meter.initMutex.map(new KyoSequencer(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KyoSttpMonad extends MonadAsyncError[M]:
handleWrappedError(rt)(h)

def ensure[A](f: M[A], e: => M[Unit]) =
Promise.init[Nothing, Unit].map { p =>
Promise.initWith[Nothing, Unit] { p =>
def run =
Async.run(e).map(p.become).unit
IO.ensure(run)(f).map(r => p.get.andThen(r))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kyo.*

object KyoUtil:
def nettyChannelFutureToScala(nettyFuture: ChannelFuture)(using Frame): Channel < Async =
Promise.init[Nothing, Channel].map { p =>
Promise.initWith[Nothing, Channel] { p =>
p.onComplete(_ => IO(nettyFuture.cancel(true)).unit).andThen {
nettyFuture.addListener((future: ChannelFuture) =>
discard {
Expand All @@ -20,7 +20,7 @@ object KyoUtil:
}

def nettyFutureToScala[A](f: io.netty.util.concurrent.Future[A])(using Frame): A < Async =
Promise.init[Nothing, A].map { p =>
Promise.initWith[Nothing, A] { p =>
p.onComplete(_ => IO(f.cancel(true)).unit).andThen {
f.addListener((future: io.netty.util.concurrent.Future[A]) =>
discard {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private[netty] class NettyKyoRequestBody(val createFile: ServerRequest => KyoStt
contentLength: Option[Long],
maxBytes: Option[Long]
): KyoSttpMonad.M[Array[Byte]] =
Promise.init[Nothing, Array[Byte]].map { p =>
Promise.initWith[Nothing, Array[Byte]] { p =>
val fut = SimpleSubscriber.processAll(publisher, contentLength, maxBytes)
fut.onComplete { r =>
import AllowUnsafe.embrace.danger
Expand Down

0 comments on commit fa19dd5

Please sign in to comment.