Skip to content

Commit 4f6f300

Browse files
committed
refactor(Batching)!: Relax arbitrary arrays constraint
1 parent 856c655 commit 4f6f300

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Equinox.Core/Batching.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ type internal AsyncBatch<'Req, 'Res>() =
1818
// sadly there's no way to detect without a try/catch
1919
try queue.TryAdd(item)
2020
with :? InvalidOperationException -> false
21-
let mutable attempt = Unchecked.defaultof<Lazy<Task<'Res[]>>>
21+
let mutable attempt = Unchecked.defaultof<Lazy<Task<'Res>>>
2222

2323
/// Attempt to add a request to the flight
2424
/// Succeeds during linger interval (which commences when the first caller triggers the workflow via AwaitResult)
2525
/// Fails if this flight has closed (caller should initialize a fresh Batch, potentially holding off until the current attempt completes)
26-
member _.TryAdd(req, dispatch: Func<'Req[], CancellationToken, Task<'Res[]>>, lingerMs: int, limiter: System.Threading.SemaphoreSlim voption, ct) =
26+
member _.TryAdd(req, dispatch: Func<'Req[], CancellationToken, Task<'Res>>, lingerMs: int, limiter: System.Threading.SemaphoreSlim voption, ct) =
2727
if not (tryEnqueue req) then false else
2828

29-
// Prepare a new instance, with cancellation under our control (it won't start until the Force triggers it though)
30-
let newInstance: Lazy<Task<'Res[]>> = lazy task {
29+
// Prepare a new instance, with cancellation under our control (it won't start until the .Value triggers it though)
30+
let newInstance: Lazy<Task<'Res>> = lazy task {
3131
do! Task.Delay(lingerMs, ct)
3232
match limiter with ValueNone -> () | ValueSome s -> do! s.WaitAsync(ct)
3333
try queue.CompleteAdding()
@@ -45,12 +45,12 @@ type internal AsyncBatch<'Req, 'Res>() =
4545
/// Requests are added to pending batch during the wait period, which consists of two phases:
4646
/// 1. a defined linger period (min 1ms)
4747
/// 2. (optionally) a wait to acquire capacity on a limiter semaphore (e.g. one might have a limit on concurrent dispatches across a pool)
48-
type Batcher<'Req, 'Res> private (tryInclude: Func<AsyncBatch<_, _>, 'Req, CancellationToken, bool>) =
48+
type Batcher<'Req, 'Res> private (tryInclude: Func<AsyncBatch<'Req, 'Res>, 'Req, CancellationToken, bool>) =
4949
let mutable cell = AsyncBatch<'Req, 'Res>()
50-
new(dispatch: Func<'Req[], CancellationToken, Task<'Res[]>>, lingerMs, limiter) =
50+
new(dispatch: Func<'Req[], CancellationToken, Task<'Res>>, lingerMs, limiter) =
5151
if lingerMs < 1 then invalidArg (nameof(lingerMs)) "Minimum linger period is 1ms" // concurrent waiters need to add work to the batch across their threads
5252
Batcher(fun cell req ct -> cell.TryAdd(req, dispatch, lingerMs, limiter, ct = ct))
53-
new(dispatch: 'Req[] -> Async<'Res[]>, ?linger : TimeSpan,
53+
new(dispatch: 'Req[] -> Async<'Res>, ?linger: TimeSpan,
5454
// Extends the linger phase to include a period during which we await capacity on an externally managed Semaphore
5555
// The Batcher doesn't care, but a typical use is to enable limiting the number of concurrent in-flight dispatches
5656
?limiter) =

0 commit comments

Comments
 (0)