Skip to content

Control DataLoader using an IDisposable? #11

@njlr

Description

@njlr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions