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
package foo.bar | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.runBlocking | |
import kotlinx.coroutines.* | |
private val testingScope = CoroutineScope(CoroutineName("TestingScope")) |
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
launch(CoroutineName("Coroutine:B-2") + SupervisorJob(coroutineContext[Job])) { | |
// ... | |
} |
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
object ExceptionTester3 { | |
private val singleThreadedDispatcher = Executors.newSingleThreadExecutor { runnable -> | |
Thread(runnable).apply { | |
// Set uncaught exception handler for the thread | |
// setUncaughtExceptionHandler { _, exception -> println("UncaughtExceptionHandler : $exception") } | |
} | |
}.asCoroutineDispatcher() | |
private val testingScope = CoroutineScope(singleThreadedDispatcher) | |
@JvmStatic |
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
internal class ChildHandleNode( | |
@JvmField val childJob: ChildJob | |
) : JobCancellingNode(), ChildHandle { | |
override val parent: Job get() = job | |
override fun invoke(cause: Throwable?) = childJob.parentCancelled(job) | |
override fun childCancelled(cause: Throwable): Boolean = job.childCancelled(cause) | |
} |
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
// Standalone Coroutine | |
override fun handleJobException(exception: Throwable): Boolean { | |
handleCoroutineException(context, exception) | |
return true | |
} | |
public fun handleCoroutineException(context: CoroutineContext, exception: Throwable) { | |
try { | |
context[CoroutineExceptionHandler]?.let { | |
it.handleException(context, exception) |
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 fun cancelParent(cause: Throwable): Boolean { | |
if (isScopedCoroutine) return true | |
val isCancellation = cause is CancellationException | |
val parent = parentHandle | |
if (parent === null || parent === NonDisposableHandle) { | |
return isCancellation | |
} |
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 fun finalizeFinishingState(state: Finishing, proposedUpdate: Any?): Any? { | |
// ... | |
if (finalException != null) { | |
val handled = cancelParent(finalException) || handleJobException(finalException) | |
if (handled) (finalState as CompletedExceptionally).makeHandled() | |
} | |
// ... | |
} |
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
fun fetchPrimaryInfo() = viewModelScope.launch { | |
val appInfoDeferred = async { fetchAppInfoUseCase().execute() } | |
val userInfoDeferred = async { fetchUserInfoUseCase().execute() } | |
runCatching { | |
PrimaryInfo( | |
appInfo = appInfoDeferred.await(), | |
userInfo = userInfoDeferred.await(), | |
) | |
}.onSuccess { primaryInfo -> |
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
package io.github.myungpyo.simplekspsample.sample | |
import android.os.Bundle | |
class MainActivityStateBinding { | |
fun save(stateHolder: MainActivity, stateStore: Bundle) { | |
with(stateHolder) { | |
stateStore.putString("StickyState_stringProp", stateHolder.stringProp) | |
stateStore.putInt("StickyState_intProp", stateHolder.intProp) |
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
class MainActivity : AppCompatActivity() { | |
private val stateBinding = MainActivityStateBinding() | |
@StickyState | |
var stringProp: String = "aaa" | |
@StickyState | |
var intProp: Int = 1 |
NewerOlder