From ffa617183e43f2529824ec5b7a5abc26670edef9 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sat, 28 Jun 2014 21:08:15 -0400 Subject: [PATCH] if a task is canceled before it is run, then it will throw a canceled exception --- src/thread/task.cpp | 5 ++++- src/thread/thread_d.hpp | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/thread/task.cpp b/src/thread/task.cpp index 98edbd3..c3e1feb 100644 --- a/src/thread/task.cpp +++ b/src/thread/task.cpp @@ -35,7 +35,10 @@ namespace fc { } void task_base::run_impl() { try { - _run_functor( _functor, _promise_impl ); + if( !canceled() ) + _run_functor( _functor, _promise_impl ); + else + FC_THROW_EXCEPTION( canceled_exception, "${description}", ("description", get_desc() ) ); } catch ( const exception& e ) { diff --git a/src/thread/thread_d.hpp b/src/thread/thread_d.hpp index 6e26720..8f0abbe 100644 --- a/src/thread/thread_d.hpp +++ b/src/thread/thread_d.hpp @@ -341,6 +341,7 @@ namespace fc { bool run_next_task() { check_for_timeouts(); task_base* next = dequeue(); + if( next ) { next->_set_active_context( current ); current->cur_task = next;