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 laterDico
12/31/2018, 6:10 PMCoroutineScope
withContext
has little cost when the thread is already the targetdave08
12/31/2018, 6:12 PMwith
on one of themSam
12/31/2018, 7:36 PMdave08
12/31/2018, 8:48 PMSam
12/31/2018, 8:52 PMoverride fun onButtonClicked() = viewModelScope.launch {
doSomething() // suspend function
}
runBlocking {
viewModel.onButtonClicked().join()
verify( ...)
}
dave08
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" )
}
dave08
12/31/2018, 8:56 PMit
in runBlocking is its scope...it
as the scope, no?Sam
12/31/2018, 8:59 PMrunBlocking {
launch {
delay( 1000 )
println( "first finished" )
}
println( "outer finished" )
}
dave08
12/31/2018, 9:01 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" )
}
dave08
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 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.suspend fun asdf(): R
by default instead of fun asdfAsync(): SomeJobType<R>
as your default way of thinkingdiesieben07
01/01/2019, 12:21 PMsuspend
it is.dave08
01/01/2019, 12:26 PMdiesieben07
01/01/2019, 12:26 PM