-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
In some situations I think it would be easier to control DataLoader batching using an IDisposable. The idea is that the asyncs get batched until the handle is disposed. I think this would be easier to get right than the Async.SwitchToContext approach.
let handleQuery query : Async<Async<Response>> =
async {
use! fetchFollowersContext = DataLoader.createDisposableContext ()
let fetchFollowersLoader =
DataLoader.create fetchFollowersContext fetchFollowersBatchFn
// do! Async.SwitchToContext fetchCompanyContext // Not required
let! resultAsync = handleUserQuery fetchFollowersLoader query
return resultAsync
} // fetchFollowersContext drops out of scope so `Dispose()` is called and the batch begins
Is this possible with the current primitives and would it work well in practice?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels