diff options
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | Cargo.toml | 16 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | src/task.rs | 13 |
7 files changed, 37 insertions, 10 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index afec74b..d3b06d7 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "e6daa4ff3caadb73c7a7ddc40034fb02430ccec8" + "sha1": "de0c79d171e95d1cbbd4becf678cc43ea689551e" }, "path_in_vcs": "" }
\ No newline at end of file @@ -42,7 +42,7 @@ rust_library { host_supported: true, crate_name: "async_task", cargo_env_compat: true, - cargo_pkg_version: "4.1.0", + cargo_pkg_version: "4.2.0", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 668bd12..fe87187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Version 4.2.0 + +- Add `Task::is_finished`. (#19) + # Version 4.1.0 - Add `FallibleTask`. (#21) @@ -13,14 +13,24 @@ edition = "2018" rust-version = "1.39" name = "async-task" -version = "4.1.0" +version = "4.2.0" authors = ["Stjepan Glavina <stjepang@gmail.com>"] exclude = ["/.*"] description = "Task abstraction for building executors" -keywords = ["futures", "task", "executor", "spawn"] -categories = ["asynchronous", "concurrency", "no-std"] +keywords = [ + "futures", + "task", + "executor", + "spawn", +] +categories = [ + "asynchronous", + "concurrency", + "no-std", +] license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/async-task" + [dev-dependencies.atomic-waker] version = "1" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index b1ae509..7dc7c73 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -3,7 +3,7 @@ name = "async-task" # When publishing a new version: # - Update CHANGELOG.md # - Create "v4.x.y" git tag -version = "4.1.0" +version = "4.2.0" authors = ["Stjepan Glavina <stjepang@gmail.com>"] edition = "2018" rust-version = "1.39" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/async_task/async_task-4.1.0.crate" + value: "https://static.crates.io/crates/async_task/async_task-4.2.0.crate" } - version: "4.1.0" + version: "4.2.0" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 6 + day: 22 } } diff --git a/src/task.rs b/src/task.rs index fff918c..7d1c433 100644 --- a/src/task.rs +++ b/src/task.rs @@ -395,6 +395,19 @@ impl<T> Task<T> { let header = ptr as *const Header; unsafe { &*header } } + + /// Returns `true` if the current task is finished. + /// + /// Note that in a multithreaded environment, this task can change finish immediately after calling this function. + pub fn is_finished(&self) -> bool { + let ptr = self.ptr.as_ptr(); + let header = ptr as *const Header; + + unsafe { + let state = (*header).state.load(Ordering::Acquire); + state & (CLOSED | COMPLETED) != 0 + } + } } impl<T> Drop for Task<T> { |