Last active
October 13, 2025 20:36
-
-
Save taig/b64f95d67a8c10cf865925a0a176f670 to your computer and use it in GitHub Desktop.
Revisions
-
taig revised this gist
Feb 2, 2020 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,7 @@ import cats.implicits._ import org.scalajs.dom.html.Image import org.scalajs.dom.{document, Event} def loadImage[F[_]](url: String)(implicit F: ConcurrentEffect[F]): F[Boolean] = for { promise <- Deferred[F, Boolean] image <- F.delay(document.createElement("img").asInstanceOf[Image]) -
taig renamed this gist
Feb 2, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
taig revised this gist
Feb 2, 2020 . 2 changed files with 23 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ import cats.effect.concurrent.Deferred import cats.effect.implicits._ import cats.effect.{ConcurrentEffect, IO} import cats.implicits._ import org.scalajs.dom.html.Image import org.scalajs.dom.{document, Event} def loadImage[F[_]]( url: String )(implicit F: ConcurrentEffect[F]): F[Boolean] = for { promise <- Deferred[F, Boolean] image <- F.delay(document.createElement("img").asInstanceOf[Image]) register = { (event: String, result: Boolean) => val listener = (_: Event) => promise.complete(result).runAsync(_ => IO.unit).unsafeRunSync() F.delay(image.addEventListener(event, listener)) } _ <- register("load", true) _ <- register("error", false) _ <- F.delay(image.src = url) result <- promise.get } yield result This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +0,0 @@ -
taig revised this gist
Feb 2, 2020 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,7 @@ import org.scalajs.dom.html.Image import org.scalajs.dom.{Event, document} object Util { def loadImage[F[_]](url: String)(implicit F: ConcurrentEffect[F]): F[Boolean] = for { promise <- Deferred[F, Boolean] image <- F.delay(document.createElement("img").asInstanceOf[Image]) -
taig created this gist
Feb 2, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ import cats.effect.concurrent.Deferred import cats.effect.implicits._ import cats.effect.{ConcurrentEffect, IO} import cats.implicits._ import org.scalajs.dom.html.Image import org.scalajs.dom.{Event, document} object Util { def loadImage[F[_]]( url: String )(implicit F: ConcurrentEffect[F]): F[Boolean] = for { promise <- Deferred[F, Boolean] image <- F.delay(document.createElement("img").asInstanceOf[Image]) register = { (event: String, result: Boolean) => val listener = (_: Event) => promise.complete(result).runAsync(_ => IO.unit).unsafeRunSync() F.delay(image.addEventListener(event, listener)) } _ <- register("load", true) _ <- register("error", false) _ <- F.delay(image.src = url) result <- promise.get } yield result }