Giter Site home page Giter Site logo

Comments (9)

amory avatar amory commented on June 14, 2024 3

It's better to let users decide what async library they'd like to use. Callbacks are easily integrated with core.async (and Manifold).

from lacinia.

candid82 avatar candid82 commented on June 14, 2024

@hlship I think it'd be helpful to have an example of a resolver for async scenario. Did you consider embracing core.async instead of creating customer API for async resolvers? Would it be possible to allow resolvers return a channel that conveys regular resolver result (ResolvedTuple or anything else)? This would be similar to how pedestal handles async.

from lacinia.

hlship avatar hlship commented on June 14, 2024
(defn gizmo-resolver
    [context args value]
    (let [result (resolve-deferred)]
      (do-in-a-new-thread
        (->> value read-gizmo (resolve-async! result)))
      tuple))

from lacinia.

mpenet avatar mpenet commented on June 14, 2024

It also seems to me it's something that could be solved using
core.async promise-chan, it's essentially the "deferred" you describe
and since a lot of async stuff (db libraries for instance) in clojure are interfaced with
core.async this would play nicely with them, and allow to plug timeouts and
whatnot at the resolver level super easily with alts!

(defn gizmo-resolver
    [context args value]
    (let [prom (async/promise-chan)]
      (do-in-a-new-thread
        (->> value read-gizmo (async/put! prom)))
      prom)) 

About the "executor" context side of things (your ex with do-in-a-new-thread), I like the idea of letting the end user use whatever he likes and not bake in a complex executor/query planner in lacinia. Then if the user wants to spin the jobs in a vanilla ExecutorService or via go blocks, or some other engine, he's free to do so and has full control over how this happens. In short, imho, lacinia should just define an async container for resolve return value and leave the rest as is, so you just have to take care about the "wait" part on all the promises internally and nothing else.

from lacinia.

hlship avatar hlship commented on June 14, 2024

Normally I love core.async, but I'm also looking to avoid any further dependencies, and core.async is a big one.

from lacinia.

stijnopheide avatar stijnopheide commented on June 14, 2024

What about manifold? It's a beautiful API to work with and allows you to define a custom executor.

from lacinia.

amory avatar amory commented on June 14, 2024

I like @mpenet's suggestions. Setting timeouts and handling async execution seems outside the bounds of Lacinia.

Also, Clojure has a built-in "deferred" object api: https://clojuredocs.org/clojure.core/promise. Although I can see why it would be useful to define a new protocol.

from lacinia.

hlship avatar hlship commented on June 14, 2024

Promise is good to a point, but there isn't an option other than blocking with a timeout and polling with realized?. The point of the the when-ready! and resolve-async! is to provide a third option, where code gets executed when data is available. It's brain dead simple compared to core.async, BUT it's solving a simpler problem: a single "publisher" and single "subscriber".

from lacinia.

hlship avatar hlship commented on June 14, 2024

Made a few updates; what I long ago called ResolvedTuple was renamed to ResolverResult before 0.13.0.

from lacinia.

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.