35 lines
1.0 KiB
C++
35 lines
1.0 KiB
C++
|
|
#ifndef ADAPTERS_BOOST_ASIO_DEADLINE_TIMER_AREQ_H
|
||
|
|
#define ADAPTERS_BOOST_ASIO_DEADLINE_TIMER_AREQ_H
|
||
|
|
|
||
|
|
#include <boostAsioLinkageFix.h>
|
||
|
|
#include <functional>
|
||
|
|
#include <boost/asio/deadline_timer.hpp>
|
||
|
|
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||
|
|
#include <adapters/smo/cpsCallbackAReq.h>
|
||
|
|
|
||
|
|
namespace adapters::boostAsio {
|
||
|
|
|
||
|
|
using TimerWaitCbFn = std::function<void(bool success)>;
|
||
|
|
|
||
|
|
inline auto deadlineTimerWaitAReq(
|
||
|
|
boost::asio::io_service &ioService,
|
||
|
|
const boost::posix_time::milliseconds delay)
|
||
|
|
{
|
||
|
|
return smo::cpsBoundary::CpsCallbackAReq<bool, TimerWaitCbFn, std::function<void(sscl::cps::Callback<TimerWaitCbFn>)>>(
|
||
|
|
ioService,
|
||
|
|
[&ioService, delay](sscl::cps::Callback<TimerWaitCbFn> cb)
|
||
|
|
{
|
||
|
|
auto timer = std::make_shared<boost::asio::deadline_timer>(ioService);
|
||
|
|
timer->expires_from_now(delay);
|
||
|
|
timer->async_wait(
|
||
|
|
[timer, cb](const boost::system::error_code &error) mutable
|
||
|
|
{
|
||
|
|
cb.callbackFn(!error);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace adapters::boostAsio
|
||
|
|
|
||
|
|
#endif // ADAPTERS_BOOST_ASIO_DEADLINE_TIMER_AREQ_H
|