Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Nov 15, 2024
1 parent 5f81147 commit c8bc3e7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Compiler/Facilities/AsyncMemoize.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type private KeyData<'TKey, 'TVersion> =
Version: 'TVersion
}

type Job<'t> = AsyncLazy<Result<'t, ExceptionDispatchInfo> * CapturingDiagnosticsLogger>
type Job<'t> = AsyncLazy<Result<'t, exn> * CapturingDiagnosticsLogger>

[<DebuggerDisplay("{DebuggerDisplay}")>]
type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'TVersion: equality
Expand All @@ -153,6 +153,7 @@ type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'T
let eventCounts = [for j in JobEvent.AllEvents -> j, ref 0] |> dict
let mutable hits = 0
let mutable duration = 0L
let mutable events_in_flight = 0

let keyTuple (keyData: KeyData<_, _>) = keyData.Label, keyData.Key, keyData.Version

Expand Down Expand Up @@ -194,12 +195,11 @@ type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'T
let! result = computation
log Finished key
Interlocked.Add(&duration, sw.ElapsedMilliseconds) |> ignore
return (Result.Ok result), logger
return Result.Ok result, logger
with
| ex ->
log Failed key
let edi = ExceptionDispatchInfo.Capture(ex)
return Result.Error edi, logger
return Result.Error ex, logger
}

let getOrAdd () =
Expand Down Expand Up @@ -232,9 +232,8 @@ type internal AsyncMemoize<'TKey, 'TVersion, 'TValue when 'TKey: equality and 'T
match result with
| Ok result ->
return result
| Error edi ->
edi.Throw()
return raise edi.SourceException
| Error ex ->
return raise ex
}

member _.TryGet(key: 'TKey, predicate: 'TVersion -> bool) : 'TValue option =
Expand Down

0 comments on commit c8bc3e7

Please sign in to comment.