Skip to content

Commit

Permalink
(#141) EmulsionXmpp: avoid waiting for child workflow when not required
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Sep 26, 2021
1 parent 7014390 commit b639ca2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Emulsion/Xmpp/EmulsionXmpp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ let private withTimeout title (logger: ILogger) workflow (timeout: TimeSpan) = a
let! child = Async.StartChild(workflow, int timeout.TotalMilliseconds)

let! childWaiter = Async.StartChild(async {
let! _ = child
return Some true
let! result = child
return Some(ValueSome result)
})

let waitTime = timeout * 1.5
let timeoutWaiter = async {
do! Async.Sleep waitTime
return Some false
return Some ValueNone
}

let! completedInTime = Async.Choice [| childWaiter; timeoutWaiter |]
match completedInTime with
| Some true -> return! child
| Some(ValueSome r) -> return r
| _ ->
logger.Information(
"Task {Title} neither complete nor cancelled in {Timeout}. Entering extended wait mode.",
Expand All @@ -64,7 +64,7 @@ let private withTimeout title (logger: ILogger) workflow (timeout: TimeSpan) = a
)
let! completedInTime = Async.Choice [| childWaiter; timeoutWaiter |]
match completedInTime with
| Some true -> return! child
| Some(ValueSome r) -> return r
| _ ->
logger.Warning(
"Task {Title} neither complete nor cancelled in another {Timeout}. Trying to cancel forcibly by terminating the client.",
Expand Down

0 comments on commit b639ca2

Please sign in to comment.