Files
myxlib/src/myx/redis/request-inl.hpp

47 lines
958 B
C++

#ifndef MYX_REDIS_REQUEST_INL_HPP_
#define MYX_REDIS_REQUEST_INL_HPP_
#pragma once
#include <myx/base/config.hpp>
#ifndef MYXLIB_HEADER_ONLY
#include <myx/redis/request.hpp>
#endif
#include <QTimer>
namespace myx {
namespace redis {
MYXLIB_INLINE Request::Request( QObject* parent ) :
QObject( parent ),
d ( new Loop )
{
connect( this, &Request::reply, this, &Request::deleteLater );
}
MYXLIB_INLINE bool Request::waitForReply( int msecs )
{
QTimer timer;
timer.setInterval( msecs );
timer.setSingleShot( true );
connect( &timer, &QTimer::timeout, &d->m_loop, &QEventLoop::quit );
connect( this, &Request::reply, d.data(), &Loop::quitEventLoop );
/*
* If the timer fires, the return value will be 0.
* Otherwise, quitEventLoop() will terminate the loop with 1.
*/
return( ( d->m_loop.exec( QEventLoop::ExcludeUserInputEvents ) != 0 ) );
}
} // namespace redis
} // namespace myx
#endif // ifndef MYX_REDIS_REQUEST_INL_HPP_