Giter Site home page Giter Site logo

Comments (4)

matthewgertner avatar matthewgertner commented on May 3, 2024 4

@leebyron My colleague made a similar point to me. Presumably one major advantage of DataLoader is that it batches load calls when the occur on the same tick. If you say something like:

const foo = await dataLoader.load(...)
const bar = await dataLoader.load(...)
const baz = await dataLoader.load(...)

...then Node will execute each call in a separate tick and no batching will be possible (at least this is my understanding).

Am I misunderstanding something or do you just think that the convenience of await outweighs the benefits of batching?

from dataloader.

leebyron avatar leebyron commented on May 3, 2024

Just to follow up on this: async/await not only does not remove the benefits of DataLoader, it's actually a quite nice way to use DataLoader. async/await is a syntactic way to operate on Promises, and Promises are returned by the load() function.

from dataloader.

wincent avatar wincent commented on May 3, 2024

@matthewgertner: Your understanding is correct. If you want the three loads to occur concurrently you will have to avoid the serial execution ordering that await imposes. In your example, you could use Promise.all:

const [foo, bar, baz] = await Promise.all([
  dataLoader.load(...),
  dataLoader.load(...),
  dataLoader.load(...),
]);

Note that this doesn't mean you can't use await at all, just that you have to be selective where and how you use it.

from dataloader.

matthewgertner avatar matthewgertner commented on May 3, 2024

Right, thanks for the clarification.

from dataloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.