diff --git a/src/core/Akka/Pattern/CircuitBreaker.cs b/src/core/Akka/Pattern/CircuitBreaker.cs index 5f3691b24f8..cf0a0f00dd7 100644 --- a/src/core/Akka/Pattern/CircuitBreaker.cs +++ b/src/core/Akka/Pattern/CircuitBreaker.cs @@ -240,41 +240,19 @@ public Task WithCircuitBreaker(TState state, Func body) => CurrentState.InvokeState(state, body); /// - /// The failure will be recorded farther down. + /// Wraps invocations of asynchronous calls that need to be protected. /// - /// TBD - public void WithSyncCircuitBreaker(Action body) - { - var cbTask = WithCircuitBreaker(body,(b) => Task.Factory.StartNew(b)); - if (!cbTask.Wait(CallTimeout)) - { - //throw new TimeoutException( string.Format( "Execution did not complete within the time allotted {0} ms", CallTimeout.TotalMilliseconds ) ); - } - if (cbTask.Exception != null) - { - ExceptionDispatchInfo.Capture(cbTask.Exception).Throw(); - } - } + /// Call needing protected + public void WithSyncCircuitBreaker(Action body) => + WithCircuitBreaker(body, b => Task.Run(b)).GetAwaiter().GetResult(); /// - /// Wraps invocations of asynchronous calls that need to be protected - /// If this does not complete within the time allotted, it should return default() - /// - /// - /// Await.result( - /// withCircuitBreaker(try Future.successful(body) catch { case NonFatal(t) ⇒ Future.failed(t) }), - /// callTimeout) - /// - /// + /// Wraps invocations of asynchronous calls that need to be protected. /// - /// TBD - /// TBD - /// or default() - public T WithSyncCircuitBreaker(Func body) - { - var cbTask = WithCircuitBreaker(body,(b) => Task.Factory.StartNew(b)); - return cbTask.Wait(CallTimeout) ? cbTask.Result : default(T); - } + /// Call needing protected + /// The result of the call + public T WithSyncCircuitBreaker(Func body) => + WithCircuitBreaker(body, b => Task.Run(b)).Result; /// /// Mark a successful call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the