Skip to content

Commit

Permalink
Remove WFFacilities::ReplyGuard.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Aug 31, 2024
1 parent 4c39519 commit 72a3116
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
14 changes: 0 additions & 14 deletions docs/tutorial-05-http_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,3 @@ int process(WFHttpTask *server_task)
series_of(server_task)->push_back(task);
}
~~~
但鉴于很多用户不想了解series用法,我们加入一个便利类ReplyGuard,让用户可以在任何时候回复请求,用法如下:
~~~cpp
int process(WFHttpTask *server_task)
{
auto *guard = new WFFacilities::ReplyGuard(server_task);
WFHttpTask *task = WFTaskFactory::create_http_task(..., [guard, server_task]{WFHttpTask *task) {
*server_task->get_resp() = std::move(*task->get_resp());
delete guard; // 此时server才会回复。
});
task->start();
}
~~~
WFFacilities::ReplyGuard用于阻止一个server task的回复,只有这个guard被析构,才会触发回复。
使用ReplyGuard一般不影响原server task series的使用,用户依然可以push_back任务。但**避免再调用series的cancel()**。
22 changes: 0 additions & 22 deletions src/manager/WFFacilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,6 @@ class WFFacilities
WFFuture<void> future;
};

public:
class ReplyGuard
{
public:
ReplyGuard(SubTask *server_task)
{
SeriesWork *series = series_of(server_task);
assert(series);
assert(server_task == series->get_last_task());
this->cond = WFTaskFactory::create_conditional(server_task);
series->set_last_task(this->cond);
}

~ReplyGuard()
{
this->cond->signal(NULL);
}

private:
WFConditional *cond;
};

private:
static void __timer_future_callback(WFTimerTask *task);
static void __fio_future_callback(WFFileIOTask *task);
Expand Down

0 comments on commit 72a3116

Please sign in to comment.