Skip to content

Commit

Permalink
cleanup AsyncBlockingCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 17, 2024
1 parent eae8294 commit 1318068
Showing 1 changed file with 0 additions and 50 deletions.
50 changes: 0 additions & 50 deletions src/FSharp.Data.Adaptive/Datastructures/Index.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,56 +155,6 @@ type IndexNode =

#if !FABLE_COMPILER

type internal AsyncBlockingCollection<'a>() =
let store = System.Collections.Generic.Queue<'a>()

let mutable next : option<Tasks.TaskCompletionSource<unit>> = None //Tasks.TaskCompletionSource<unit>()

member x.Add(value : 'a) =
lock store (fun () ->
store.Enqueue value
match next with
| Some n ->
n.SetResult()
next <- None
| None ->
()
)

member x.Take() =
Async.FromContinuations (fun (success, error, cancel) ->
Monitor.Enter store
try
if store.Count > 0 then
let value = store.Dequeue()
Monitor.Exit store
success value
else
let tcs =
match next with
| Some n -> n
| None ->
let n = Tasks.TaskCompletionSource<unit>()
next <- Some n
n
Monitor.Exit store
tcs.Task.ContinueWith (fun (_t : Tasks.Task<unit>) ->
Async.StartWithContinuations(x.Take(), success, error, cancel)
) |> ignore
with
| :? OperationCanceledException as e ->
Monitor.Exit store
cancel e
| e ->
Monitor.Exit store
error e
)

member x.Clear() =
lock store (fun () ->
store.Clear()
)

/// datastructure representing an abstract index.
/// supported operations are: Index.zero, Index.after(index), Index.before(index), Index.between(l, r).
/// this is a 'simple' solution to the order-maintenance problem that has insert in O(log N), delete in O(1) and compare in O(1).
Expand Down

0 comments on commit 1318068

Please sign in to comment.