forked from drogonframework/drogon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the setTimeout() method to the DbClient class (drogonframework#823)
- Loading branch information
Showing
26 changed files
with
821 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* | ||
* @file TaskTimeoutFlag.cc | ||
* @author An Tao | ||
* | ||
* Copyright 2018, An Tao. All rights reserved. | ||
* https://github.com/an-tao/drogon | ||
* Use of this source code is governed by a MIT license | ||
* that can be found in the License file. | ||
* | ||
* Drogon | ||
* | ||
*/ | ||
|
||
#include "TaskTimeoutFlag.h" | ||
using namespace drogon; | ||
|
||
TaskTimeoutFlag::TaskTimeoutFlag(trantor::EventLoop *loop, | ||
const std::chrono::duration<double> &timeout, | ||
std::function<void()> timeoutCallback) | ||
: loop_(loop), timeout_(timeout), timeoutFunc_(timeoutCallback) | ||
{ | ||
} | ||
void TaskTimeoutFlag::runTimer() | ||
{ | ||
std::weak_ptr<TaskTimeoutFlag> weakPtr = shared_from_this(); | ||
loop_->runAfter(timeout_, [weakPtr]() { | ||
auto thisPtr = weakPtr.lock(); | ||
if (!thisPtr) | ||
return; | ||
if (thisPtr->done()) | ||
return; | ||
thisPtr->timeoutFunc_(); | ||
}); | ||
} | ||
bool TaskTimeoutFlag::done() | ||
{ | ||
return isDone_.exchange(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* | ||
* @file TaskTimeoutFlag.h | ||
* @author An Tao | ||
* | ||
* Copyright 2018, An Tao. All rights reserved. | ||
* https://github.com/an-tao/drogon | ||
* Use of this source code is governed by a MIT license | ||
* that can be found in the License file. | ||
* | ||
* Drogon | ||
* | ||
*/ | ||
#include <trantor/utils/NonCopyable.h> | ||
#include <trantor/net/EventLoop.h> | ||
#include <chrono> | ||
#include <functional> | ||
#include <atomic> | ||
#include <memory> | ||
|
||
namespace drogon | ||
{ | ||
class TaskTimeoutFlag : public trantor::NonCopyable, | ||
public std::enable_shared_from_this<TaskTimeoutFlag> | ||
{ | ||
public: | ||
TaskTimeoutFlag(trantor::EventLoop *loop, | ||
const std::chrono::duration<double> &timeout, | ||
std::function<void()> timeoutCallback); | ||
bool done(); | ||
void runTimer(); | ||
|
||
private: | ||
std::atomic<bool> isDone_{false}; | ||
trantor::EventLoop *loop_; | ||
std::chrono::duration<double> timeout_; | ||
std::function<void()> timeoutFunc_; | ||
}; | ||
} // namespace drogon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.