Skip to content
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

Translate ch01-02 in french. #2

Open
wants to merge 3 commits into
base: french-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions FRENCH/examples-sources/01_02_why_async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "example_01_02_why_async"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"

[lib]

[dev-dependencies]
futures = "0.3"
47 changes: 47 additions & 0 deletions FRENCH/examples-sources/01_02_why_async/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![cfg(test)]

use {
futures::{
executor::block_on,
join,
},
std::thread,
};

fn download(_url: &str) {
// ...
}

#[test]
// ANCHOR: get_two_sites
fn get_two_sites() {
// Spawn two threads to do work.
let thread_one = thread::spawn(|| download("https://www.foo.com"));
let thread_two = thread::spawn(|| download("https://www.bar.com"));

// Wait for both threads to complete.
thread_one.join().expect("thread one panicked");
thread_two.join().expect("thread two panicked");
}
// ANCHOR_END: get_two_sites

async fn download_async(_url: &str) {
// ...
}

// ANCHOR: get_two_sites_async
async fn get_two_sites_async() {
// Create two different "futures" which, when run to completion,
// will asynchronously download the webpages.
let future_one = download_async("https://www.foo.com");
let future_two = download_async("https://www.bar.com");

// Run both futures to completion at the same time.
join!(future_one, future_two);
}
// ANCHOR_END: get_two_sites_async

#[test]
fn get_two_sites_async_test() {
block_on(get_two_sites_async());
}
1 change: 1 addition & 0 deletions FRENCH/examples-sources/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[workspace]
members = [
"01_02_why_async",
]
10 changes: 10 additions & 0 deletions FRENCH/examples/01_02_why_async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "example_01_02_why_async"
version = "0.1.0"
authors = ["Taylor Cramer <[email protected]>"]
edition = "2018"

[lib]

[dev-dependencies]
futures = "0.3"
39 changes: 39 additions & 0 deletions FRENCH/examples/01_02_why_async/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#![cfg(test)]

fn telecharger(_url: &str) {
// ...
}

#[test]
// ANCHOR: get_two_sites
fn recuperer_deux_sites() {
// Crée deux tâches pour faire le travail.
let premiere_tache = std::thread::spawn(|| telecharger("https://www.foo.com"));
let seconde_tache = std::thread::spawn(|| telecharger("https://www.bar.com"));

// Attente que les deux tâches se terminent.
premiere_tache.join().expect("la première tâche a paniqué");
seconde_tache.join().expect("la deuxième tâche a paniqué");
}
// ANCHOR_END: get_two_sites

async fn telecharger_asynchrone(_url: &str) {
// ...
}

// ANCHOR: get_two_sites_async
async fn recuperer_deux_sites_asynchrone() {
// Crée deux différentes "futures" qui, lorsqu'elles sont menée à terme,
// va télécharger les pages web de manière asynchrone.
let premier_future = telecharger_asynchrone("https://www.foo.com");
let second_future = telecharger_asynchrone("https://www.bar.com");

// Exécute les deux futures en même temps jusqu'à leur fin.
futures::join!(premier_future, second_future);
}
// ANCHOR_END: get_two_sites_async

#[test]
fn recuperer_deux_sites_asynchrone_test() {
futures::executor::block_on(recuperer_deux_sites_asynchrone());
}
1 change: 1 addition & 0 deletions FRENCH/examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[workspace]
members = [
"01_02_why_async",
]
Loading