diesieben07
12/31/2018, 5:40 PMfun foo(): Deferred<Foo>
vs. suspend fun foo(): Foo
. The code must execute on a specific dispatcher, so I could use withContext
for the suspend
version. It feels to me like suspend
is the cleaner variant. Correct?dave08
12/31/2018, 6:01 PMasync {}
and only need the result laterdave08
12/31/2018, 6:06 PMDico
12/31/2018, 6:10 PMCoroutineScope
Dico
12/31/2018, 6:10 PMDico
12/31/2018, 6:11 PMwithContext
has little cost when the thread is already the targetdave08
12/31/2018, 6:12 PMwith
on one of themdave08
12/31/2018, 6:14 PMSam
12/31/2018, 7:36 PMdave08
12/31/2018, 8:48 PMdave08
12/31/2018, 8:51 PMSam
12/31/2018, 8:52 PMSam
12/31/2018, 8:53 PMoverride fun onButtonClicked() = viewModelScope.launch {
doSomething() // suspend function
}
Sam
12/31/2018, 8:53 PMSam
12/31/2018, 8:54 PMrunBlocking {
viewModel.onButtonClicked().join()
verify( ...)
}
Sam
12/31/2018, 8:54 PMdave08
12/31/2018, 8:55 PMSam
12/31/2018, 8:55 PMrunBlocking {
val dispatcher1 : CoroutineDispatcher = coroutineContext[ContinuationInterceptor] as CoroutineDispatcher
launch(dispatcher1) {
delay( 1000 )
println( "first finished" )
}
println( "outer finished" )
}
Sam
12/31/2018, 8:56 PMdave08
12/31/2018, 8:56 PMit
in runBlocking is its scope...dave08
12/31/2018, 8:58 PMit
as the scope, no?Sam
12/31/2018, 8:59 PMSam
12/31/2018, 8:59 PMrunBlocking {
launch {
delay( 1000 )
println( "first finished" )
}
println( "outer finished" )
}
dave08
12/31/2018, 9:01 PMdave08
12/31/2018, 9:02 PMdave08
12/31/2018, 9:03 PMdave08
12/31/2018, 9:04 PMdave08
12/31/2018, 9:05 PMSam
12/31/2018, 9:05 PMrunBlocking {
val scope = CoroutineScope( coroutineContext + <http://Dispatchers.IO|Dispatchers.IO> )
scope.launch {
delay( 1000 )
println( "first finished" )
}
println( "outer finished" )
}
Sam
12/31/2018, 9:05 PMSam
12/31/2018, 9:09 PMdave08
12/31/2018, 9:10 PMit
instead of coroutineContext
? I can't test it out i'm not on a computer now 🙂Sam
12/31/2018, 9:13 PMSam
12/31/2018, 9:14 PMSam
12/31/2018, 9:15 PMgroostav
12/31/2018, 11:35 PMpublic async Task doStuff()
in C#, where I forgot to await
the return value because its effectively void, and I got the resulting typical concurrent heisenbugs.groostav
12/31/2018, 11:36 PMsuspend fun asdf(): R
by default instead of fun asdfAsync(): SomeJobType<R>
as your default way of thinkingdiesieben07
01/01/2019, 12:21 PMdiesieben07
01/01/2019, 12:24 PMsuspend
it is.dave08
01/01/2019, 12:26 PMdiesieben07
01/01/2019, 12:26 PM