-
Notifications
You must be signed in to change notification settings - Fork 343
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
Conversation
6c74517
to
2dfdc1c
Compare
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
brandonros
commented
Nov 12, 2019
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 spawn
ing tasks into something that main
can then block on is much more realistic.
d7fa0cc
to
1431ee0
Compare
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
@ghost
ghost
left a comment
There was a problem hiding this 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 <yoshuawuyts@gmail.com>
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))
}
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