<div dir="ltr"><div dir="ltr">You can either check in the completion handler that `ex.running_in_this_thread() == true` or wrap the inner executor and use a thread-local variable to determine whether a current thread is running in the executor&#39;s context.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 25, 2019 at 4:50 PM Cristian Morales Vega &lt;<a href="mailto:cristian@samknows.com">cristian@samknows.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 6 Dec 2018 at 23:59, Damian Jarek &lt;<a href="mailto:damian.jarek93@gmail.com" target="_blank">damian.jarek93@gmail.com</a>&gt; wrote:<br>
&gt; Here&#39;s an example of what might happen if a composed operation doesn&#39;t maintain work guards properly:<br>
&gt; <a href="https://wandbox.org/permlink/aqsGDNJWTmFd7PdC" rel="noreferrer" target="_blank">https://wandbox.org/permlink/aqsGDNJWTmFd7PdC</a><br>
&gt;<br>
&gt; Without the work_guard the coroutine never completes. If you add the work_guard, everything works correctly.<br>
<br>
If I were to do something stupid like<br>
<a href="https://wandbox.org/permlink/sIpX20mQdaHgjESz" rel="noreferrer" target="_blank">https://wandbox.org/permlink/sIpX20mQdaHgjESz</a><br>
- Hide executor_type making it private<br>
- Use the handler executor type for the work guard<br>
<br>
What would be the best way to unit test async_foo() to detect the problems?<br>
<br>
I guess I could derive from io_context to get the steady_timer to use<br>
an intermediate executor that would forward everything to the<br>
io_context::get_executor but keeping record of the work count, and<br>
bind a similar fake executor to check the dispatch calls. But there<br>
may be a more clever/simpler way?<br>
</blockquote></div></div>