mirror of
https://github.com/sogou/workflow.git
synced 2026-10-29 03:27:04 +08:00
Add mailbox task's factory functions
This commit is contained in:
@@ -620,6 +620,14 @@ public:
|
||||
this->mailbox = mailbox;
|
||||
}
|
||||
|
||||
WFMailboxTask(std::function<void (WFMailboxTask *)>&& cb) :
|
||||
next(&this->user_data),
|
||||
value(2),
|
||||
callback(std::move(cb))
|
||||
{
|
||||
this->mailbox = &this->user_data;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~WFMailboxTask() { }
|
||||
};
|
||||
|
||||
@@ -293,6 +293,33 @@ void WFTaskFactory::count_by_name(const std::string& counter_name, unsigned int
|
||||
__CounterMap::get_instance()->count_n(counter_name, n);
|
||||
}
|
||||
|
||||
/********MailboxTask*************/
|
||||
|
||||
class __WFMailboxTask : public WFMailboxTask
|
||||
{
|
||||
public:
|
||||
__WFMailboxTask(size_t size, mailbox_callback_t&& cb) :
|
||||
WFMailboxTask(new void *[size], size, std::move(cb))
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~__WFMailboxTask()
|
||||
{
|
||||
delete []this->mailbox;
|
||||
}
|
||||
};
|
||||
|
||||
WFMailboxTask *WFTaskFactory::create_mailbox_task(size_t size,
|
||||
mailbox_callback_t callback)
|
||||
{
|
||||
return new __WFMailboxTask(size, std::move(callback));
|
||||
}
|
||||
|
||||
WFMailboxTask *WFTaskFactory::create_mailbox_task(mailbox_callback_t callback)
|
||||
{
|
||||
return new WFMailboxTask(std::move(callback));
|
||||
}
|
||||
|
||||
/********FileIOTask*************/
|
||||
|
||||
class WFFilepreadTask : public WFFileIOTask
|
||||
|
||||
@@ -90,6 +90,7 @@ using fsync_callback_t = std::function<void (WFFileSyncTask *)>;
|
||||
using timer_callback_t = std::function<void (WFTimerTask *)>;
|
||||
using counter_callback_t = std::function<void (WFCounterTask *)>;
|
||||
|
||||
// Mailbox is like counter with data passing
|
||||
using mailbox_callback_t = std::function<void (WFMailboxTask *)>;
|
||||
|
||||
// Graph (DAG) task.
|
||||
@@ -229,6 +230,9 @@ public:
|
||||
static WFMailboxTask *create_mailbox_task(size_t size,
|
||||
mailbox_callback_t callback);
|
||||
|
||||
/* Use 'user_data' as mailbox. Store only one message. */
|
||||
static WFMailboxTask *create_mailbox_task(mailbox_callback_t callback);
|
||||
|
||||
public:
|
||||
template<class FUNC, class... ARGS>
|
||||
static WFGoTask *create_go_task(const std::string& queue_name,
|
||||
|
||||
Reference in New Issue
Block a user