Skip to content

Commit

Permalink
threadsafe events collection
Browse files Browse the repository at this point in the history
  • Loading branch information
majocha committed Nov 9, 2024
1 parent a88665c commit a6e175c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ let tap f x = f x; x

let internal record (cache: AsyncMemoize<_,_,_>) =

let events = ResizeArray()
let events = Collections.Concurrent.ConcurrentQueue()

let waitForIdle() = SpinWait.SpinUntil(fun () -> not cache.Updating)

waitForIdle()
cache.Event
|> Event.map (fun (e, (_, k, _)) -> e, k)
|> Event.add events.Add
|> Event.add events.Enqueue

let getEvents () =
waitForIdle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let fileName fileId = $"File%s{fileId}.fs"

let internal recordAllEvents groupBy =
let mutable cache : AsyncMemoize<_,_,_> option = None
let events = ResizeArray()
let events = ConcurrentQueue()

let waitForIdle() = SpinWait.SpinUntil(fun () -> not cache.Value.Updating)

Expand All @@ -40,7 +40,7 @@ let internal recordAllEvents groupBy =
waitForIdle()
cache.Value.Event
|> Event.map (fun (e, k) -> groupBy k, e)
|> Event.add events.Add
|> Event.add events.Enqueue

let getEvents () =
waitForIdle()
Expand Down

0 comments on commit a6e175c

Please sign in to comment.