1//
2// AsyncReader.cpp
3//
4// Library: Redis
5// Package: Redis
6// Module: AsyncReader
7//
8// Implementation of the AsyncReader class.
9//
10// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#include "Poco/Redis/AsyncReader.h"
18
19
20namespace Poco {
21namespace Redis {
22
23
24AsyncReader::AsyncReader(Client& client):
25 _client(client),
26 _activity(this, &AsyncReader::runActivity)
27{
28}
29
30
31AsyncReader::~AsyncReader()
32{
33 stop();
34}
35
36
37void AsyncReader::runActivity()
38{
39 while (!_activity.isStopped())
40 {
41 try
42 {
43 RedisType::Ptr reply = _client.readReply();
44
45 RedisEventArgs args(reply);
46 redisResponse.notify(this, args);
47
48 if ( args.isStopped() ) stop();
49 }
50 catch (Exception& e)
51 {
52 RedisEventArgs args(&e);
53 redisException.notify(this, args);
54 stop();
55 }
56 if (!_activity.isStopped()) Thread::trySleep(100);
57 }
58}
59
60
61} } // namespace Poco::Redis
62