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! + }); +```