Derek Berner
03/04/2019, 8:36 PM<http://Dispatchers.IO|Dispatchers.IO>
, that is. Specifically, our backend is MS SQL Server.Dias
03/05/2019, 9:22 AMfun test() = coroutineScope {
launch()
launch()
}
is using
fun test() = withContext(...) {
launch()
launch()
}
equivalent to that? apart from the part where you need to pass some context element in itDias
03/05/2019, 9:23 AMlouiscad
03/05/2019, 11:26 AMsuspend fun cancelNow(): Nothing = suspendCancellableCoroutine<Nothing> { c -> c.cancel() }
mboudraa
03/05/2019, 1:37 PM@Test
fun `should receive updated data when querying all challenges`() {
val initChallenges = mutableListOf(Challenge(...),Challenge(...))
val newSurveyChallenge = SurveyChallenge(...)
val expectedChallenges = listOf(
initChallenges,
initChallenges += newSurveyChallenge
)
initChallenges.forEach(challengeDao::addOrUpdate)
runBlocking {
val channel = repository.availableChallenges(coroutineContext)
val actualChallengesLists = async(IO) {
channel.fold(mutableListOf<List<Challenge>>()) { list, challenges -> list.apply { add(challenges) } }
}
delay(300)
challengeDao.addOrUpdate(newSurveyChallenge)
delay(300)
channel.cancel()
assertThat(actualChallengesLists.await()).containsExactlyElementsIn(expectedChallenges).inOrder()
}
without those delay
, my test fail because the database doesnt have the time to notify anything. But having a delay looks like a code smell to me.
Is there a better way to test this behavior?
For the record I use sqldelight
and robolectric
to test thatsitepodmatt
03/06/2019, 9:24 AMobject CoroutineCrashTest {
private val scope = GlobalScope + Job()
fun run() = scope.launch(Dispatchers.Default) {
doAwaitInside()
}
private suspend fun doAwaitInside() {
supervisorScope {
try {
testAsync().await()
} catch (e: IllegalStateException) {
// catched but still crash
}
}
}
private fun testAsync() = scope.async(Dispatchers.Default) {
throw IllegalStateException("test")
}
}
sitepodmatt
03/06/2019, 9:24 AMghedeon
03/06/2019, 1:36 PMGlobalScope.rxFlowable{}
?Seri
03/06/2019, 7:01 PMCompletableDeferred
. I’m using it to wrap an Android UI prompt, so I’m setting a lateinit var CompletableDeferred
before launching the prompt, then completing it from the system callback once the user action is complete. However, the var is always null
when I try to complete it. Is there an obvious flaw here, or a better approach?Wouter Vegter
03/07/2019, 9:19 AMvngantk
03/07/2019, 9:23 AMOleh Ponomarenko
03/07/2019, 10:07 AMMarcelo Hernandez
03/07/2019, 7:05 PMcancelChildren()
while never explicitly cancelling the parent Job
itself? This way when onStart()
is called, you can continue reusing the Job
for launching more coroutines?Jag
03/07/2019, 11:22 PMbasher
03/08/2019, 5:55 AMdeviant
03/08/2019, 3:02 PMprivate suspend fun <E> ReceiveChannel<E>.throttle(): ReceiveChannel<E> {
// want to launch {} in current scope
}
mp
03/08/2019, 3:04 PMObjectReader#readValue()
inside a suspending function, I get an inspection warning that it's an "Inappropriate blocking method call". However, I'm calling the variant that deserializes from a string, so there's no blocking i/o. Also I still get the warning if I throw that logic onto another dispatcher. What can I do about the warning other than suppress it?Hexa
03/08/2019, 4:28 PMpardom
03/08/2019, 4:29 PMmatiaslev
03/08/2019, 5:34 PMbjonnh
03/08/2019, 11:16 PMbjonnh
03/08/2019, 11:19 PMDico
03/09/2019, 1:09 PMwithScope
instead of withContext
. Now you have to write withContext(myScope.coroutineContext)
but, given the intended purpose 😉 of CoroutineScope
, I feel there should be a scope variant of it.thana
03/10/2019, 3:52 PMbjonnh
03/11/2019, 4:05 AMproduce<String>(capacity = 1024) {
input.forEachLine { async { send(it) } }
}.map {
async {
val tokenized = tokenizerFactory.create(pp.preProcess(it)).tokens.joinToString(" ")
tokenized + "\n"
}
}.map {
output.appendText(it.await())
}
spand
03/11/2019, 9:38 AMDispatchers.setMain
also coming for js ?trathschlag
03/11/2019, 12:45 PMfun main() {
runBlocking {
val job = launch {
suspendCoroutine<Unit> {}
}
yield()
job.cancel()
println("goodbye")
}
println("exit")
}
prints
goodbye
and then hangs forever. Does anybody know why this happens? When removing the yield()
it just works as expected.Slackbot
03/11/2019, 1:10 PMahulyk
03/11/2019, 1:21 PMlaunch {
val first = async(IO) {
transactionDataRepository.getFist()
}
val second = async(IO) {
transactionDataRepository.getSecond()
}
}
and
launch {
withContext(IO) {
val first = async {
transactionDataRepository.getFist()
}
val second = async {
transactionDataRepository.getSecond()
}
}
}
???Giorgio Antonioli
03/11/2019, 1:48 PMBroadcastChannel
.
private val getChannel = BroadcastChannel<String>(1)
fun myApiCallbackNotSuspended() {
runBlocking {
println("X")
getChannel.send("result")
println("Y")
}
}
suspend fun get(): String {
val receiveChannel = getChannel.openSubscription()
println("A")
// It will invoke "myApiCallbackNotSuspended()" on the main thread after some time.
myApiCall()
println("B")
val result = receiveChannel.receive()
println("C)
return result
}
The method myApiCallbackNotSuspended()
is invoked and it sends the result to the channel.
The problem is that receiveChannel.receive()
remains stuck.
I get the message in the following order: A B X Y without getting CGiorgio Antonioli
03/11/2019, 1:48 PMBroadcastChannel
.
private val getChannel = BroadcastChannel<String>(1)
fun myApiCallbackNotSuspended() {
runBlocking {
println("X")
getChannel.send("result")
println("Y")
}
}
suspend fun get(): String {
val receiveChannel = getChannel.openSubscription()
println("A")
// It will invoke "myApiCallbackNotSuspended()" on the main thread after some time.
myApiCall()
println("B")
val result = receiveChannel.receive()
println("C)
return result
}
The method myApiCallbackNotSuspended()
is invoked and it sends the result to the channel.
The problem is that receiveChannel.receive()
remains stuck.
I get the message in the following order: A B X Y without getting Cmarstran
03/11/2019, 1:53 PMmyApiCall
as well, so we can reproduce it?Giorgio Antonioli
03/11/2019, 2:10 PMmyApiCall
is a method inside a library which is not open-source. I tried to reproduce the same behavior with another library and it works.
It seems something related to "myApiCall" and channels used together. TBH I have no clue on what to check now.