|
|
|
@ -127,6 +127,20 @@ namespace Grpc.Core |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// cached handler for watch connectivity state |
|
|
|
|
static readonly BatchCompletionDelegate WatchConnectivityStateHandler = (success, ctx, state) => |
|
|
|
|
{ |
|
|
|
|
var tcs = (TaskCompletionSource<object>) state; |
|
|
|
|
if (success) |
|
|
|
|
{ |
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
tcs.SetCanceled(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Returned tasks completes once channel state has become different from |
|
|
|
|
/// given lastObservedState. |
|
|
|
@ -138,18 +152,8 @@ namespace Grpc.Core |
|
|
|
|
"Shutdown is a terminal state. No further state changes can occur."); |
|
|
|
|
var tcs = new TaskCompletionSource<object>(); |
|
|
|
|
var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture; |
|
|
|
|
var handler = new BatchCompletionDelegate((success, ctx) => |
|
|
|
|
{ |
|
|
|
|
if (success) |
|
|
|
|
{ |
|
|
|
|
tcs.SetResult(null); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
tcs.SetCanceled(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
handle.WatchConnectivityState(lastObservedState, deadlineTimespec, completionQueue, handler); |
|
|
|
|
// pass "tcs" as "state" for WatchConnectivityStateHandler. |
|
|
|
|
handle.WatchConnectivityState(lastObservedState, deadlineTimespec, completionQueue, WatchConnectivityStateHandler, tcs); |
|
|
|
|
return tcs.Task; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|