Skip to content

Commit

Permalink
Add Striped reading
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 20, 2019
1 parent c566681 commit 9a4463d
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 124 deletions.
21 changes: 21 additions & 0 deletions equinox-sync/Sync/Infrastructure.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[<AutoOpen>]
module private SyncTemplate.Infrastructure

open Equinox.Store // AwaitTaskCorrect
open System
open System.Threading
open System.Threading.Tasks
Expand All @@ -17,3 +18,23 @@ type Async with
let rec callback _ = Task.Run(fun () -> if Interlocked.Increment isDisposed = 1 then d.Dispose() ; sc ()) |> ignore
and d : IDisposable = Console.CancelKeyPress.Subscribe callback
in ())

type SemaphoreSlim with
/// F# friendly semaphore await function
member semaphore.Await(?timeout : TimeSpan) = async {
let! ct = Async.CancellationToken
let timeout = defaultArg timeout Timeout.InfiniteTimeSpan
let task = semaphore.WaitAsync(timeout, ct)
return! Async.AwaitTaskCorrect task
}

module Queue =
let tryDequeue (x : System.Collections.Generic.Queue<'T>) =
#if NET461
if x.Count = 0 then None
else x.Dequeue() |> Some
#else
match x.TryDequeue() with
| false, _ -> None
| true, res -> Some res
#endif
Loading

0 comments on commit 9a4463d

Please sign in to comment.