coroutine support like go.
If Nim is compiled to C, will it be difficult to support coroutine ??
There is co-routine support via import coro https://nim-lang.org/docs/coro.html
Though I think what you are looking for is asyncdispatch for async/await: https://nim-lang.org/docs/asyncdispatch.html
And channels in Nim are for parallelism: https://nim-lang.org/docs/channels.html.
Asyncdispatch futures should be enough for synchronizing/communicating between async tasks.
Also can you detail use-cases, even in pseudo-code so that we know:
There is co-routine support via
import corohttps://nim-lang.org/docs/coro.htmlThough I think what you are looking for is asyncdispatch for async/await: https://nim-lang.org/docs/asyncdispatch.html
And channels: https://nim-lang.org/docs/channels.htmlAlso can you detail use-cases, even in pseudo-code so that we know:
- what you have in mind
- if maybe we don't already have support for that
- if it can be implemented as a library or if it needs compiler support
We need lightweight thread support to deal with high concurrency when we implement web services. Equivalent to threads
#[async_std::main]
async fn main() {
let id = task::current().id();
println!("{:?}", id);
let task = task::spawn(async {
let id = task::current().id();
println!("{:?}", id);
task::sleep(Duration::from_millis(1000)).await;
});
println!("waiting for the task");
let res = task.await;
println!("task ended with result {:?}", res);
}
for i := 0; i < ncpu; i++ {
go func() {
for {
select {
case <-done:
return
case ch <- Must(NewUUID()):
}
}
}()
}
There is co-routine support via
import corohttps://nim-lang.org/docs/coro.htmlThough I think what you are looking for is asyncdispatch for async/await: https://nim-lang.org/docs/asyncdispatch.html
And channels in Nim are for parallelism: https://nim-lang.org/docs/channels.html.
Asyncdispatch futures should be enough for synchronizing/communicating between async tasks.Also can you detail use-cases, even in pseudo-code so that we know:
- what you have in mind
- if maybe we don't already have support for that
- if it can be implemented as a library or if it needs compiler support
It co-routine very difficult to use. The best thing is that Nim officially supports async await。
Of course, Nim can also provide future interfaces for other projects to implement。just like rust lang done
I think theres lot of misunderstanding about naming and terminology here.
Nim has async/await. You can implement your own Types that use Futures.
Jester/HTTPBeast use threads for implementing web services and stuff.
If you want to use Nim with Rust like syntax you can create a Nim module that mimic its look&feel,
kinda like https://github.com/Yardanico/nimpylib#nimpylib mimics Python using metaprogramming.
See also https://github.com/treeform/greenlet for a Nim coroutine implementation based upon cgreenlet.
Most helpful comment
See also https://github.com/treeform/greenlet for a Nim coroutine implementation based upon cgreenlet.