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 $(D_PSYMBOL something()) is not cancelled. From the point of view of $(D_PSYMBOL something()), the cancellation did not happen. But its caller is still cancelled, so the call still raises $(D_PSYMBOL CancelledException). Note: If $(D_PSYMBOL something()) is cancelled by other means this will still cancel $(D_PSYMBOL shield()).

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

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

shield
(
Coroutine
Args...
)

Meta