Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Document example for 2..N long-running function calls "in parallel" or "joined"? #105

Open
moorage opened this issue May 28, 2018 · 0 comments

Comments

@moorage
Copy link

moorage commented May 28, 2018

I'm a new-comer to rust, particularly to futures and async/await; however, I'm pretty familiar with coroutines and some of the javascript libraries like async-parallel.

I'm aiming to call 2 (or N) long-running async functions, and wait for them both to finish before continuing.

I did a fair bit of googling, and couldn't find any examples in rust of something along these lines in rust.

Here's how one might do it in javascript...

async.parallel({
    one: function(callback) { callback(null, 'done1\n'); },
    two: function(callback) { callback(null, 'done2\n'); }
}, function(err, results) {
    // now we can continue
});

Or in golang...

    messages := make(chan int)

    go func() {
        time.Sleep(time.Second * 3)
        messages <- 1
        done <- true
    }()
    go func() {
        time.Sleep(time.Second * 2)
        messages <- 2
        done <- true
    }() 
    for i := 0; i < 2; i++ {
        <-done
    }

   // now we can continue

Any chance we could add an example of this to the documentation?

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

No branches or pull requests

1 participant