From 573deec14bf6fdcb7353706030bade6299c24e94 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Fri, 22 Sep 2023 20:04:25 +0200 Subject: [PATCH] CoapRequestBase - Added `get(Duration)` which times out after the provided time has elapsed --- source/doap/client/request.d | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/doap/client/request.d b/source/doap/client/request.d index 9a1904f..0b4b182 100644 --- a/source/doap/client/request.d +++ b/source/doap/client/request.d @@ -340,4 +340,25 @@ public class CoapRequestFuture return this.response; } + public CoapPacket get(Duration timeout) + { + // We can only wait on a condition if we + // ... first have a-hold of the lock + this.mutex.lock(); + + // Await a response + if(this.condition.wait(timeout)) + { + // Upon waking up release lock + this.mutex.unlock(); + + return this.response; + } + else + { + // TODO: Make this a specific exception so the user can easily check for it + // ... (see feature/cancellable_future for how this would need to be update) + throw new CoapException("Timed out whilst waiting"); + } + } } \ No newline at end of file