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

Enforce exception transparency in SafeFlow #1657

Closed
qwwdfsad opened this issue Nov 12, 2019 · 0 comments
Closed

Enforce exception transparency in SafeFlow #1657

qwwdfsad opened this issue Nov 12, 2019 · 0 comments
Labels

Comments

@qwwdfsad
Copy link
Member

We can enforce it by caching and checking any exception that was thrown by downstream.emit.
The trick is to have (almost) the same performance as before while giving up on tail-call.
For that, we can use a trick with "reusable continuation" as in TakeFlowCollector.

Enforcing this invariant is crucial, otherwise, it may lead to really weird interactions, for example, consider the following pipeline:

val flow = flow {
    try {
        emit(1)
    } catch (e: Throwable) {
        emit(2)
    }
}

// Somewhere on consumer side
flow.collect {
    println("Processed '$it' and expecting no more elements")
    throw CancellationException()
}

collect lambda will be invoked twice even though it threw an exception on the first emit

@qwwdfsad qwwdfsad added the flow label Nov 12, 2019
qwwdfsad added a commit that referenced this issue Feb 10, 2020
…n transparency invariant on JVM

    * Make it in allocation-free manner by using crafty trick with casting KSuspendFunction to Function and pass reusable object as a completion

Fixes #1657
qwwdfsad added a commit that referenced this issue Feb 10, 2020
…n transparency invariant on JVM

    * Make it in allocation-free manner by using crafty trick with casting KSuspendFunction to Function and pass reusable object as a completion

Fixes #1657
qwwdfsad added a commit that referenced this issue Feb 10, 2020
…n transparency invariant on JVM

    * Make it in allocation-free manner by using crafty trick with casting KSuspendFunction to Function and pass reusable object as a completion

Fixes #1657
qwwdfsad added a commit that referenced this issue Feb 10, 2020
…n transparency invariant on JVM

    * Make it in allocation-free manner by using crafty trick with casting KSuspendFunction to Function and pass reusable object as a completion

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

No branches or pull requests

1 participant