mirror of
https://github.com/deavmi/doap
synced 2024-07-04 16:50:19 +02:00
CoapRequestBase
- Added `get(Duration)` which times out after the provided time has elapsed
This commit is contained in:
parent
05557fc63c
commit
573deec14b
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user