Giter VIP home page Giter VIP logo

Comments (7)

TimonPost avatar TimonPost commented on July 24, 2024

Interesting I will take a look into this. I agree that the threads are probably not the best here.

from crossterm.

imdaveho avatar imdaveho commented on July 24, 2024

Is there a reason that async / await would be better? I am intending to use crossterm as a library to wrap Python. Threads seems to be a more cross platform compatible mechanism to achieve concurrency. I could be wrong though, but I'm also not a huge fan of eventloops where languages already provide you safety guarantees with threads...is there really a benefit that I'm not aware of?

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

Agreed, bringing in event loops, async await futures might increase the complexity of crossterm. The one thread we have will exist for a little time and will be closed after that. I think it is not much needed to bring more complexity in.

from crossterm.

prabirshrestha avatar prabirshrestha commented on July 24, 2024

The main reason for me was if we could avoid thread sleep here and avoid wasting CPU cycles sepcially on laptops.

https://github.com/TimonPost/crossterm/blob/c37a480f78c8c1ca020271ae6902d453122955e9/crossterm_input/examples/async_input.rs#L36

My thought was that using async/await if there is some sort of mpsc::Receiver or Streams then internally it doesn't matter whether it using thread of eventloop sine the consumer of the api wouldn't need to worry about changing the api.

let input_stream = input().read_async_with_threads(); // or input().read_async_witheventloop();
while let Some(inputEvent) = await!(input_stream().next()) {
    // do something with inputEvent
}

As for the actual perf I'm not sure which one is better but in terms of battery life I think eventloops are better.

You do bring up a good point where threads are more portable so it does seems good to have that as an option.

We should wait for generators/streams to finalize first.

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

Agree that async and await might be better however it is does not have good support yet in rust. If we want to use async await need to use Tokio/futures or something which I like to stay far a way from with crossterm. Maybe 'awaiting' for rust to introduce async and await is the best idea here.

from crossterm.

prabirshrestha avatar prabirshrestha commented on July 24, 2024

I agree we should wait for rust to stabilize async await first.

from crossterm.

TimonPost avatar TimonPost commented on July 24, 2024

This could be closed, we stick with threads, #79 is fixed which kind of relates to this.

from crossterm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.