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

The comments for 'ReceiveChannel.receiveCatching' are confusing. #3888

Closed
CoenQian opened this issue Sep 18, 2023 · 1 comment
Closed

The comments for 'ReceiveChannel.receiveCatching' are confusing. #3888

CoenQian opened this issue Sep 18, 2023 · 1 comment
Labels
channels docs KDoc and API reference

Comments

@CoenQian
Copy link

What do we have now?

ReceiveChannel.receiveCatching

CleanShot 2023-09-18 at 20 10 47@2x

I am confused by the comments marked with underlines:

  1. If the Job of the current coroutine is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException.
  2. If the job was cancelled while this function was suspended, it will not resume successfully.

When I try to translate them into Chinese, I feel like they're the same thing.

Keywords in two lines:

  1. If job is cancelled or completed while this function is suspended, this function immediately resumes with a CancellationException.
  2. If job was cancelled while this function was suspended, this function will not resume successfully.

The differences in keywords between the two lines of text are listed below:

line job be cancelled function be suspended when result
1st line is is immediately resume
2nd line was was will not resume

Thanks for your patience.

My question is "why the result of two lines are different?".

What should be instead?

From my pespectives, the result of two lines should be same.

Maybe designer of this function want to express like this:

  1. this function is(was) suspended.
  2. if the job invoking this function is(was) cancelled.
  3. this function immediately(will) resume with CancellationException(not resume successfully).

"resume with CancellationException" means "not resume successfully"

But, it is difficult for developers from non-english speaking country or kotlin coroutine beginners.

There is a good case in Channel API.

CleanShot 2023-09-18 at 20 47 48@2x

When phrase "not resume successfully" was used in the current context, the designer used "throws a CancellationException" phrase instead of "resume with a CancellationException" phrase.

Why?
Even though I am an experienced kotlin coroutine user and have readed lots of source codes of coroutine library, i still felt confused when i read this comment for the first time.

As the result of two lines are different (resume vs not resume), i try to analyze what's different about the environments, of course, I failed.

When i asked other developers about this issue, they also faced the same confusion as i did.

Someone even interpreted the difference between "is" and "was" as one expressing a continuous process (ending in "ing") and the other expressing a completed result (ending in "ed").

So i suggest simplifying the comments like Channel's "Prompt cancellation guarantee"

Thanks for your patience again.

@dkhalanskyjb dkhalanskyjb added docs KDoc and API reference and removed design labels Sep 18, 2023
@CoenQian
Copy link
Author

select has the same comment.
image

dkhalanskyjb added a commit that referenced this issue Feb 12, 2024
Emphasize the fact that the function fails to resume *even if it
already completed* but wasn't dispatched yet. Before the change,
when translating the documentation to Chinese, there could be a
confusion as to what "it will not resume successfully" means.

Fixes #3888
dkhalanskyjb added a commit that referenced this issue Feb 13, 2024
Emphasize the fact that the function fails to resume *even if it
already completed* but wasn't dispatched yet. Before the change,
when translating the documentation to Chinese, there could be a
confusion as to what "it will not resume successfully" means.

Fixes #3888
dkhalanskyjb added a commit that referenced this issue Feb 14, 2024
Emphasize the fact that the function fails to resume *even if it
already completed* but wasn't dispatched yet. Before the change,
when translating the documentation to Chinese, there could be a
confusion as to what "it will not resume successfully" means.

Fixes #3888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
channels docs KDoc and API reference
Projects
None yet
Development

No branches or pull requests

3 participants