Last active
December 31, 2022 19:46
-
-
Save djspiewak/d2c18448d6379d09c6eb57e7cb73c57d to your computer and use it in GitHub Desktop.
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
def raceAll[F[_], E, A](fs: List[F[A]])(implicit F: GenConcurrent[F, E]): F[A] = | |
F.deferred[Outcome[F, E, A]] flatMap { d => | |
F uncancelable { poll => | |
val fibersF = fs traverse { fa => | |
fa.guaranteeCase(d.complete(_).void).start | |
} | |
fibersF flatMap { fibers => | |
poll(d.get.guarantee(fibers.parTraverse_(_.cancel)).flatMap(_.embedNever)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment