timeoutError that takes Future<Error<T>> as input

This commit is contained in:
sramamoorthy 2019-06-27 13:53:42 -07:00 committed by Alex Miller
parent 7ec8fe6e74
commit 806a0822f1
1 changed files with 14 additions and 0 deletions

View File

@ -198,7 +198,21 @@ Future<T> timeoutError( Future<T> what, double time, TaskPriority taskID = TaskP
}
}
ACTOR template <class T>
Future<T> timeoutError( Future<ErrorOr<T>> what, double time, TaskPriority taskID = TaskPriority::DefaultDelay ) {
Future<Void> end = delay( time, taskID );
choose {
when( ErrorOr<T> t = wait( what ) ) {
if (t.isError()) {
throw t.getError();
}
return t.get();
}
when( wait( end ) ) { throw timed_out(); }
}
}
Future<T> delayed( Future<T> what, double time = 0.0, TaskPriority taskID = TaskPriority::DefaultDelay ) {
try {
state T t = wait( what );