@@ -240,41 +240,19 @@ public Task WithCircuitBreaker<TState>(TState state, Func<TState, Task> body) =>
240
240
CurrentState . InvokeState ( state , body ) ;
241
241
242
242
/// <summary>
243
- /// The failure will be recorded farther down .
243
+ /// Wraps invocations of asynchronous calls that need to be protected .
244
244
/// </summary>
245
- /// <param name="body">TBD</param>
246
- public void WithSyncCircuitBreaker ( Action body )
247
- {
248
- var cbTask = WithCircuitBreaker ( body , ( b ) => Task . Factory . StartNew ( b ) ) ;
249
- if ( ! cbTask . Wait ( CallTimeout ) )
250
- {
251
- //throw new TimeoutException( string.Format( "Execution did not complete within the time allotted {0} ms", CallTimeout.TotalMilliseconds ) );
252
- }
253
- if ( cbTask . Exception != null )
254
- {
255
- ExceptionDispatchInfo . Capture ( cbTask . Exception ) . Throw ( ) ;
256
- }
257
- }
245
+ /// <param name="body">Call needing protected</param>
246
+ public void WithSyncCircuitBreaker ( Action body ) =>
247
+ WithCircuitBreaker ( body , b => Task . Run ( b ) ) . GetAwaiter ( ) . GetResult ( ) ;
258
248
259
249
/// <summary>
260
- /// Wraps invocations of asynchronous calls that need to be protected
261
- /// If this does not complete within the time allotted, it should return default(<typeparamref name="T"/>)
262
- ///
263
- /// <code>
264
- /// Await.result(
265
- /// withCircuitBreaker(try Future.successful(body) catch { case NonFatal(t) ⇒ Future.failed(t) }),
266
- /// callTimeout)
267
- /// </code>
268
- ///
250
+ /// Wraps invocations of asynchronous calls that need to be protected.
269
251
/// </summary>
270
- /// <typeparam name="T">TBD</typeparam>
271
- /// <param name="body">TBD</param>
272
- /// <returns><typeparamref name="T"/> or default(<typeparamref name="T"/>)</returns>
273
- public T WithSyncCircuitBreaker < T > ( Func < T > body )
274
- {
275
- var cbTask = WithCircuitBreaker ( body , ( b ) => Task . Factory . StartNew ( b ) ) ;
276
- return cbTask . Wait ( CallTimeout ) ? cbTask . Result : default ( T ) ;
277
- }
252
+ /// <param name="body">Call needing protected</param>
253
+ /// <returns>The result of the call</returns>
254
+ public T WithSyncCircuitBreaker < T > ( Func < T > body ) =>
255
+ WithCircuitBreaker ( body , b => Task . Run ( b ) ) . Result ;
278
256
279
257
/// <summary>
280
258
/// Mark a successful call through CircuitBreaker. Sometimes the callee of CircuitBreaker sends back a message to the
0 commit comments