Function shield

Wait for a future, shielding it from cancellation.

The statement

res = shield(something());

is exactly equivalent to the statement

res = something();

except that if the coroutine containing it is cancelled, the task running in something() is not cancelled. From the point of view of something(), the cancellation did not happen. But its caller is still cancelled, so the call still raises CancelledException.

Prototype

auto shield(Coroutine, Args...)(
  EventLoop eventLoop,
  Coroutine coroutine,
  Args args
);

Note

If something() is cancelled by other means this will still cancel shield().

If you want to completely ignore cancellation (not recommended) you can combine shield() with a try/catch clause, as follows:

   try
       res = shield(something());
   catch (CancelledException)
       res = null;
 

Authors

Dragos Carp

Copyright

© 2015-2016 Dragos Carp

License

Boost Software License - Version 1.0