Рефакторинг библиотеки для Redis
This commit is contained in:
53
src/myx/redis/request-inl.hpp
Normal file
53
src/myx/redis/request-inl.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
#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 <myx/redis/request_p.hpp>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace redis {
|
||||
|
||||
void RequestPrivate::quitEventLoop()
|
||||
{
|
||||
loop.exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
Request::Request( QObject* parent ) :
|
||||
QObject( parent ),
|
||||
d ( new RequestPrivate )
|
||||
{
|
||||
connect( this, &Request::reply, this, &Request::deleteLater );
|
||||
}
|
||||
|
||||
|
||||
bool Request::waitForReply( int msecs )
|
||||
{
|
||||
QTimer timer;
|
||||
timer.setInterval( msecs );
|
||||
timer.setSingleShot( true );
|
||||
|
||||
connect( &timer, &QTimer::timeout, &d->loop, &QEventLoop::quit );
|
||||
connect( this, &Request::reply, d.data(), &RequestPrivate::quitEventLoop );
|
||||
|
||||
/*
|
||||
* If the timer fires, the return value will be 0.
|
||||
* Otherwise, quitEventLoop() will terminate the loop with 1.
|
||||
*/
|
||||
return( ( d->loop.exec( QEventLoop::ExcludeUserInputEvents ) != 0 ) );
|
||||
}
|
||||
|
||||
} // namespace redis
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_REDIS_REQUEST_INL_HPP_
|
Reference in New Issue
Block a user