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

Consider using spawn and channel in specific async runtime. #608

Open
Berrysoft opened this issue Oct 3, 2021 · 5 comments
Open

Consider using spawn and channel in specific async runtime. #608

Berrysoft opened this issue Oct 3, 2021 · 5 comments

Comments

@Berrysoft
Copy link

I see that EventStream is using std::thread and std::sync::mpsc at now. It is of course an improvement according to #448. However, I'd like to suggest a possible improvement, with the usage of spawn and channels in specific async runtime, for example, tokio or async-std. Therefore, the async runtime could manage the event stream thread.

The replacement in tokio is spawn and mpsc.

The replacement in async-std is spawn and channel.

Both of them should be drop-in replacement, rewritting some functions to async ones. I'd like to open a pull request later, trying to add the implementation as an optional feature, and keep the original implementation as a fallback one.

@Berrysoft Berrysoft mentioned this issue Oct 3, 2021
4 tasks
@BoolPurist
Copy link

BoolPurist commented Sep 13, 2024

I agree that the underlying stream should not used to spawn a naked OS-thread outside any async runtime.

The previous attempt to fix this seems to go back quite a while.

I am willing to pick this up from here.

However, I have a few questions before starting the rewrite.

  1. Is still there now any interest in the rewrite ?
  2. How to do it in terms of the compile features ? I have the following suggestion.
  • Only supporting tokio under the flag "event-stream"
  • The flag "event-stream" is working the context of tokio.
    One new compiler flag "asyn-std" is then using asyn-std.
  • Two new flags "tokio" and "asyn-std" in which tokio and asyn-std are respectively used.
    In this variant, I would deprecate the flag "event-stream" and type EventStream simply
    since the implementation of this type with naked OS thread should not be used anymore
    going forward in my opinion.

@Berrysoft
Copy link
Author

Is still there now any interest in the rewrite?

No, sorry. Now I think that it is easy enough for the users of tokio or other async runtimes to write another stream without spawing new threads.

@BoolPurist
Copy link

Is still there now any interest in the rewrite?

No, sorry. Now I think that it is easy enough for the users of tokio or other async runtimes to write another stream without spawing new threads.

Fair enough.
One question remains for me: shouldn't the usage of this feature then be discouraged/deprecated ?

@Berrysoft
Copy link
Author

I think it may be better to add some comments in the doc about the spawnned thread, and suggest the user to write a runtime-specific one if they care about the overhead.

@BoolPurist
Copy link

I can go ahead and add this fact to the docs about the type EvenStream. While I am at it, I would also add those comments to the example with tokio or asyn-std using this type.

BoolPurist added a commit to BoolPurist/crossterm that referenced this issue Sep 14, 2024
…Stream

This pull request is motivated by the discussion of the following
[issue](crossterm-rs#608)
BoolPurist added a commit to BoolPurist/crossterm that referenced this issue Sep 14, 2024
…Stream

This pull request is motivated by the discussion of the following
[issue](crossterm-rs#608)
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

Successfully merging a pull request may close this issue.

2 participants