Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException when using GlobalScope with CoroutineScope.peripheral in 0.28.0 #622

Open
JonatanPlesko opened this issue Jan 16, 2024 · 1 comment

Comments

@JonatanPlesko
Copy link

Trying to get the peripheral using GlobalScope as a receiver for the CoroutineScope.peripheral extension function in the latest version (0.28.0) throws the following exception:

java.lang.IllegalStateException: Current context doesn't contain Job in it: com.myproject.di.modules.DomainModule$createConnectionScope$$inlined$CoroutineExceptionHandler$1@3595913
    at kotlinx.coroutines.JobKt__JobKt.getJob(Job.kt:645)
    at kotlinx.coroutines.JobKt.getJob(Unknown Source:1)
    at com.juul.kable.BluetoothDeviceAndroidPeripheral.<init>(BluetoothDeviceAndroidPeripheral.kt:74)
    at com.juul.kable.PeripheralKt.peripheral(Peripheral.kt:30)
    at com.juul.kable.PeripheralKt.peripheral(Peripheral.kt:47)
    at com.juul.kable.PeripheralKt.peripheral$default(Peripheral.kt:42)

For reference, the createConnectionScope function creates the scope which I use for all BLE operations and looks like this:

@OptIn(DelicateCoroutinesApi::class)
private fun createConnectionScope(): CoroutineScope = GlobalScope + CoroutineExceptionHandler { _, throwable ->
    Timber.e(throwable)
}

Using CoroutineScope(SupervisorJob() + Dispatchers.Default) instead of GlobalScope works. The issue is not present in 0.27.0.

@twyatt
Copy link
Member

twyatt commented Jan 17, 2024

Thanks for the regression report.
Swamped with some projects at work, but I'll try to look into it soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants