Поддержка Redis
This commit is contained in:
36
src/myx/redis/request.cpp
Normal file
36
src/myx/redis/request.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <QTimer>
|
||||
|
||||
#include <request.hpp>
|
||||
#include <request_p.hpp>
|
||||
|
||||
using namespace qxredis;
|
||||
|
||||
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 ) );
|
||||
}
|
Reference in New Issue
Block a user