Created
November 8, 2019 14:58
-
-
Save smallufo/da4445735c8c64a05e76d108428e72ba to your computer and use it in GitHub Desktop.
flow on...
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
private suspend fun method1a(longUrl: String): String { | |
return impls.asSequence().asFlow().flatMapMerge(impls.size) { impl -> | |
flow { | |
impl.getShortUrl(longUrl)?.also { | |
emit(it) | |
} | |
}.flowOn(Dispatchers.IO) | |
}.first() | |
.also { Dispatchers.IO.cancelChildren() } | |
} | |
/** | |
22:56:30,517 INFO DumbImpl - running : DefaultDispatcher-worker-4 | |
22:56:30,518 INFO NullImpl - running : DefaultDispatcher-worker-1 | |
22:56:30,517 INFO IsgdImpl - running : DefaultDispatcher-worker-5 | |
22:56:30,517 INFO TinyImpl - running : DefaultDispatcher-worker-7 | |
22:56:30,529 INFO TinyImpl$getShortUrl$2 - running Dispatchers.IO : DefaultDispatcher-worker-7 | |
22:56:30,529 INFO IsgdImpl$getShortUrl$2 - running Dispatchers.IO : DefaultDispatcher-worker-5 | |
22:56:33,233 INFO IsgdImpl$getShortUrl$2 - ISGD network call invoked | |
22:56:33,238 INFO IsgdImpl$getShortUrl$2 - returning https://is.gd/EuvYes | |
22:56:33,244 INFO UrlShorterServiceTest$testHedging$1 - result = https://is.gd/EuvYes | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment