Skip to content

Commit

Permalink
Swap Thenable for Promise in fromPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Aug 16, 2021
1 parent 8e0cc4e commit 0e5e01a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
7 changes: 2 additions & 5 deletions core/js/src/main/scala/cats/effect/IOCompanionPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cats.effect

import scalajs.js

import scala.scalajs.js.{Promise, Thenable}
import scala.scalajs.js.Thenable

private[effect] abstract class IOCompanionPlatform { this: IO.type =>

Expand All @@ -35,10 +35,7 @@ private[effect] abstract class IOCompanionPlatform { this: IO.type =>
apply(thunk)
}

def fromThenable[A](iot: IO[Thenable[A]]): IO[A] =
asyncForIO.fromThenable(iot)

def fromPromise[A](iop: IO[Promise[A]]): IO[A] =
def fromPromise[A](iop: IO[Thenable[A]]): IO[A] =
asyncForIO.fromPromise(iop)

def realTimeDate: IO[js.Date] = asyncForIO.realTimeDate
Expand Down
10 changes: 4 additions & 6 deletions kernel/js/src/main/scala/cats/effect/kernel/AsyncPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package cats.effect.kernel

import scala.scalajs.js.{|, defined, Function1, JavaScriptException, Promise, Thenable}
import scala.scalajs.js.{|, defined, Function1, JavaScriptException, Thenable}

private[kernel] trait AsyncPlatform[F[_]] { this: Async[F] =>

def fromPromise[A](iop: F[Promise[A]]): F[A] = fromThenable(widen(iop))

def fromThenable[A](iot: F[Thenable[A]]): F[A] =
flatMap(iot) { t =>
def fromPromise[A](iop: F[Thenable[A]]): F[A] =
flatMap(iop) { p =>
async_[A] { cb =>
val onFulfilled: Function1[A, Unit | Thenable[Unit]] =
(v: A) => cb(Right(v)): Unit | Thenable[Unit]
Expand All @@ -37,7 +35,7 @@ private[kernel] trait AsyncPlatform[F[_]] { this: Async[F] =>
cb(Left(e)): Unit | Thenable[Unit]
}

t.`then`[Unit](onFulfilled, defined(onRejected))
p.`then`[Unit](onFulfilled, defined(onRejected))

()
}
Expand Down

0 comments on commit 0e5e01a

Please sign in to comment.