-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from dapper91/dev
- Library api reimplemented. - Tests added. - github actions added.
- Loading branch information
Showing
15 changed files
with
716 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: release | ||
|
||
on: | ||
release: | ||
types: | ||
- released | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Rust | ||
run: rustup update stable | ||
- name: Build and publish | ||
run: | | ||
cargo login ${{ secrets.CRATESIO_TOKEN }} | ||
cargo publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- dev | ||
- master | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
name: Test coachman | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install Rust | ||
run: rustup update stable | ||
- name: Run tests | ||
run: cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# CoachMan | ||
|
||
![coachman](img/logo.png) | ||
|
||
`coachman` is a rust asynchronous task manager built on top of tokio framework. | ||
|
||
## Features | ||
|
||
* **Task count control:** | ||
`coachman` allows you to control task count preventing your application from uncontrolled task count explosion. | ||
* **Task cancellation:** | ||
The main feature of `coachman` is task cancellation. It provides a simple api for making your task cancelable. | ||
|
||
# Basic example | ||
|
||
The main feature of coachman is making asynchronous tasks cancelable. | ||
|
||
Look at the following example: | ||
|
||
``` rust | ||
use coachman as cm; | ||
use coachman::{try_await, Canceled, Completed, TaskError}; | ||
|
||
async fn inner_func(i: usize, duration: u64) { | ||
match try_await!(tokio::time::sleep(std::time::Duration::from_secs(duration))) { | ||
Canceled => println!("task#{} inner canceled", i), | ||
Completed(_) => println!("task#{} inner completed", i), | ||
} | ||
} | ||
|
||
async fn outer_func(i: usize, duration: u64) { | ||
match try_await!(inner_func(i, duration)) { | ||
Canceled => println!("task#{} outer canceled", i), | ||
Completed(_) => println!("task#{} outer completed", i), | ||
} | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
let mut task_handles = Vec::new(); | ||
for i in 0..5 { | ||
let duration = i as u64; | ||
task_handles.push(cm::spawn(outer_func(i, duration))); | ||
} | ||
|
||
let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(2); | ||
for (i, mut handle) in task_handles.into_iter().enumerate() { | ||
if tokio::time::timeout_at(deadline, &mut handle).await.is_ok() { | ||
println!("task-{} completed", i); | ||
} else { | ||
handle.cancel(); | ||
match handle.await { | ||
Result::Err(TaskError::Canceled) => println!("task-{} canceled", i), | ||
Result::Err(TaskError::Aborted) => println!("task-{} aborted", i), | ||
Result::Err(TaskError::Panicked(_)) => println!("task-{} panicked", i), | ||
Result::Ok(_) => unreachable!(), | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use coachman as cm; | ||
use coachman::{try_await, Canceled, Completed, TaskError}; | ||
|
||
async fn inner_func(i: usize, duration: u64) { | ||
match try_await!(tokio::time::sleep(std::time::Duration::from_secs(duration))) { | ||
Canceled => println!("task#{} inner canceled", i), | ||
Completed(_) => println!("task#{} inner completed", i), | ||
} | ||
} | ||
|
||
async fn outer_func(i: usize, duration: u64) { | ||
match try_await!(inner_func(i, duration)) { | ||
Canceled => println!("task#{} outer canceled", i), | ||
Completed(_) => println!("task#{} outer completed", i), | ||
} | ||
} | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
let mut task_handles = Vec::new(); | ||
for i in 0..5 { | ||
let duration = i as u64; | ||
task_handles.push(cm::spawn(outer_func(i, duration))); | ||
} | ||
|
||
let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(2); | ||
for (i, mut handle) in task_handles.into_iter().enumerate() { | ||
if tokio::time::timeout_at(deadline, &mut handle).await.is_ok() { | ||
println!("task-{} completed", i); | ||
} else { | ||
handle.cancel(); | ||
match handle.await { | ||
Result::Err(TaskError::Canceled) => println!("task-{} canceled", i), | ||
Result::Err(TaskError::Aborted) => println!("task-{} aborted", i), | ||
Result::Err(TaskError::Panicked(_)) => println!("task-{} panicked", i), | ||
Result::Ok(_) => unreachable!(), | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.