Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.
This repository was 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

@moorage

Description

@moorage

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions