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

Remove @ExperimentalCoroutinesApi from CancellableContinuation.resume(...) #4088

Open
swankjesse opened this issue Apr 5, 2024 · 2 comments
Assignees

Comments

@swankjesse
Copy link

I’d like to use this overload of CancellableContinuation.resume() in OkHttp’s coroutines extension.

    @ExperimentalCoroutinesApi // since 1.2.0
    public fun resume(value: T, onCancellation: ((cause: Throwable) -> Unit)?)

Unfortunately, this functino is experimental. There’s no stable alternative that combines continuations with safe resource management. I’m going to annotate our own API with @ExperimentalCoroutinesApi to pass the responsibility to our callers.

I’d like for you to consider removing the experimental annotation from this function. It hasn’t changed since 2020. It solves an important very nicely!

@qwwdfsad
Copy link
Member

qwwdfsad commented Apr 5, 2024

We've been sitting on that for a while for quite a specific reason: its signature should've been (value: T, cause: Throwable) -> Unit, otherwise, when serving its main purpose, it is a capturing lambda that always allocates, even though there are no reasons real reasons to.
Changing that, there is a variance conflict -- continuations are contravariant (in T) and functional types are covariant (out T), which forces us to fallback to @UnsafeVariance and ensure that it's sound.

There was an extended attempt (#3093) to change that and also receive a CoroutineContext as the third parameter, though this part remains questionable, and we never figured it out.

Taking into account it's experimental for so long if we are going to change the signature and deprecate it, this version is going to stay basically forever.

If you have any opinions on the current or potential API shape -- don't hesitate to tell us!

@swankjesse
Copy link
Author

Thanks for the explanation. I hadn’t expected covariance!

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

No branches or pull requests

3 participants