Skip to content

polish lib.rs examples #523

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

Merged
merged 4 commits into from
Nov 21, 2019
Merged

polish lib.rs examples #523

merged 4 commits into from
Nov 21, 2019

Conversation

yoshuawuyts
Copy link
Contributor

This updates our lib.rs examples, showing off more of what async-std can do, and somewhat simplifying what we were already doing. Additionally it should make it nicer for people from other languages to understand what async rust is about.

Closes #522. Thanks!

Screenshots

2019-11-12-230749_1920x1080

Signed-off-by: Yoshua Wuyts <[email protected]>
@brandonros
Copy link

I don't know if this is sufficient to close the issue.

const main = async function () {
  const rows = await queryDatabase()
  const apiResponse = await fetchJson()
}

I think an example that showcases multiple uses of spawning tasks into something that main can then block on is much more realistic.

Signed-off-by: Yoshua Wuyts <[email protected]>
Signed-off-by: Yoshua Wuyts <[email protected]>
@yoshuawuyts yoshuawuyts added the documentation Improvements or additions to documentation label Nov 14, 2019
@yoshuawuyts yoshuawuyts requested a review from k-nasa November 20, 2019 11:16
@yoshuawuyts yoshuawuyts added this to the 1.1.0 milestone Nov 20, 2019
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm after @k-nasa's comment on the attributes feature gets addressed.

Signed-off-by: Yoshua Wuyts <[email protected]>
@yoshuawuyts yoshuawuyts merged commit c9a2e74 into master Nov 21, 2019
@yoshuawuyts yoshuawuyts deleted the update-lib-example branch November 21, 2019 20:24
@omac777
Copy link

omac777 commented Nov 27, 2019

Here is an example that shows passing 3 arguments within a task::block_on, 2 string arguments along with a vector of strings.
It compiles/runs successfully.

use std::env::args;
use async_std::fs::File;
use async_std::io::{self, BufReader};
use async_std::prelude::*;
use async_std::task;

async fn say_hi( mypath1_ : &str, mypath2_ : &str, myFilePaths_ : &mut Vec<String>) -> io::Result<()> {
   
    task::block_on(async {
        println!("mypath1_:<<{}>>",mypath1_);
        println!("mypath2_:<<{}>>",mypath2_);
        for oneFilePath2 in myFilePaths_ {
            println!("oneFilePath2:<<{}>>", oneFilePath2);
        }

        Ok(())
    })    
}

fn main() -> io::Result<()> {
    let path1 = args().nth(1).expect("missing path argument");
    let path2 = args().nth(2).expect("missing path argument");

    let mut vsMyFilePaths : Vec<String> = Vec::new();
    vsMyFilePaths.push("blah1".to_string());
    vsMyFilePaths.push("blah2".to_string());
    vsMyFilePaths.push("blah3".to_string());
    
    task::block_on(say_hi(&path1, &path2, &mut vsMyFilePaths))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend examples to show more than just a single task::block_on
4 participants