From 9d2a4ca00f14ac72d922d0402a92626af055e26c Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sat, 17 Feb 2018 12:59:05 +0100 Subject: [PATCH] Add `QPromise::timeout` documentation --- docs/SUMMARY.md | 1 + docs/qtpromise/api-reference.md | 1 + docs/qtpromise/qpromise/timeout.md | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 docs/qtpromise/qpromise/timeout.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index f31184b..bb9c03c 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -12,6 +12,7 @@ * [.isRejected](qtpromise/qpromise/isrejected.md) * [.tap](qtpromise/qpromise/tap.md) * [.then](qtpromise/qpromise/then.md) + * [.timeout](qtpromise/qpromise/timeout.md) * [.wait](qtpromise/qpromise/wait.md) * [::all (static)](qtpromise/qpromise/all.md) * [::reject (static)](qtpromise/qpromise/reject.md) diff --git a/docs/qtpromise/api-reference.md b/docs/qtpromise/api-reference.md index 6bb5c44..02bdb82 100644 --- a/docs/qtpromise/api-reference.md +++ b/docs/qtpromise/api-reference.md @@ -11,6 +11,7 @@ * [`QPromise::isRejected`](qpromise/isrejected.md) * [`QPromise::tap`](qpromise/tap.md) * [`QPromise::then`](qpromise/then.md) +* [`QPromise::timeout`](qpromise/timeout.md) * [`QPromise::wait`](qpromise/wait.md) ### Public Static Members diff --git a/docs/qtpromise/qpromise/timeout.md b/docs/qtpromise/qpromise/timeout.md new file mode 100644 index 0000000..8cb3278 --- /dev/null +++ b/docs/qtpromise/qpromise/timeout.md @@ -0,0 +1,18 @@ +## `QPromise::timeout` + +``` +QPromise::timeout(int msec, any error = QPromiseTimeoutException) -> QPromise +``` + +This method returns a promise that will be resolved with the `input` promise's fulfillment value or rejection reason. However, if the `input` promise is not fulfilled or rejected within `msec` milliseconds, the `output` promise is rejected with `error` as the reason (`QPromiseTimeoutException` by default). + +```cpp +QPromise input = {...} +auto output = input.timeout(2000) + .then([](int res) { + // operation succeeded within 2 seconds + }) + .fail([](const QPromiseTimeoutException& e) { + // operation timed out! + }); +```