From e6379daa19c7da91f1cd6d3bcf5424f495d67d02 Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Fri, 5 Jul 2019 14:41:06 -0500 Subject: [PATCH] Export istaskfailed (#32300) * Export istaskfailed * Add docstring for istaskfailed * Add news for istaskfailed --- NEWS.md | 1 + base/exports.jl | 1 + base/task.jl | 22 ++++++++++++++++++++++ doc/src/base/parallel.md | 1 + 4 files changed, 25 insertions(+) diff --git a/NEWS.md b/NEWS.md index 81fbdcca94bfd..f3ee8bb0abb56 100644 --- a/NEWS.md +++ b/NEWS.md @@ -25,6 +25,7 @@ New library functions * `findfirst`, `findlast`, `findnext` and `findprev` now accept a character as first argument to search for that character in a string passed as the second argument ([#31664]). * New `findall(pattern, string)` method where `pattern` is a string or regex ([#31834]). +* `istaskfailed` is now documented and exported, like its siblings `istaskdone` and `istaskstarted` ([#32300]). Standard library changes ------------------------ diff --git a/base/exports.jl b/base/exports.jl index 2d84157686774..22b2cca2546e7 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -646,6 +646,7 @@ export islocked, istaskdone, istaskstarted, + istaskfailed, lock, notify, ReentrantLock, diff --git a/base/task.jl b/base/task.jl index af8c2c5c302b4..71ddd551da5f4 100644 --- a/base/task.jl +++ b/base/task.jl @@ -135,6 +135,28 @@ false """ istaskstarted(t::Task) = ccall(:jl_is_task_started, Cint, (Any,), t) != 0 +""" + istaskfailed(t::Task) -> Bool + +Determine whether a task has exited because an exception was thrown. + +# Examples +```jldoctest +julia> a4() = error("task failed"); + +julia> b = Task(a4); + +julia> istaskfailed(b) +false + +julia> schedule(b); + +julia> yield(); + +julia> istaskfailed(b) +true +``` +""" istaskfailed(t::Task) = (t.state == :failed) Threads.threadid(t::Task) = Int(ccall(:jl_get_task_tid, Int16, (Any,), t)+1) diff --git a/doc/src/base/parallel.md b/doc/src/base/parallel.md index 362e6bcc977e5..453cd4562ba2c 100644 --- a/doc/src/base/parallel.md +++ b/doc/src/base/parallel.md @@ -11,6 +11,7 @@ Base.fetch(t::Task) Base.current_task Base.istaskdone Base.istaskstarted +Base.istaskfailed Base.task_local_storage(::Any) Base.task_local_storage(::Any, ::Any) Base.task_local_storage(::Function, ::Any, ::Any)