例如:
class Job{ int step; void run(){ switch(step){ case 1: step=2; doAsyncWork(..., new Callback(this)); return; case 2: step=3; ThreadPool.execute(this); return; case 3: step=4; doSyncAndBlockingWork(...); MainThread.execute(this); return; case 4: step=5; updateDatas(); ... } } }; c/c++中还可以定义一些宏来简化代码 class Job{ int step; void run(){ co_begin(this); co_yield doAsyncWork(..., this->GetCallback()); co_runasync( doSyncAndBlockingWork(...); ); updateDatas(); co_end(); } } };