Skip to content

Should assertCallingContextIsNotSuspended() only check the last stack trace element? #271

@saket

Description

@saket
Exception in thread "SDK 31 Main Thread @coroutine#76" java.lang.IllegalStateException: Calling context is suspending; use a suspending method instead
	at app.cash.turbine.CoroutinesKt.assertCallingContextIsNotSuspended(coroutines.kt:67)

I received this crash because I'm using Turbine#takeItem() from a non-suspending function:

val results = Turbine<Foo>()

fun foo(): Result {
  return results.takeItem()
}

I can probably make it suspending to fix the problem, but I was wondering if assertCallingContextIsNotSuspended() should only check the last stack item instead of finding an instance of invokeSuspend in the entire call chain?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions