Git Product home page Git Product logo

Comments (4)

armanbilge avatar armanbilge commented on June 24, 2024 2

Thanks for opening the issue! It's a good question, and I think we can revisit this design choice.

How is the Dispatcher's run different than just using the unsafe global provided?

Here are three advantages of using Dispatcher#unsafeRun over IO#unsafeRun*:

  1. You can have a dispatcher in a generic effect F[_] i.e. Dispatcher[F]
  2. A dispatcher has a scope / lifecycle i.e. it is a Resource[F, Dispatcher[F]]. You can be confident that tasks are not being leaked after the dispatcher has been closed.
  3. A Dispatcher is backed by an already running "warm" fiber. Meanwhile, IO#unsafeRun* has to do extra set-up every time it is used, e.g. registering fatal error handlers.

Should feral replace its unsafeRunSync with a Dispatcher per the advice above?

Yes and no :) point (3) above is a good motivation to create a dispatcher when the lambda starts and use it to handle all incoming requests.

The question is, how will we get that dispatcher? Since the only way to create a Dispatcher is inside of an effectful resource, but without the dispatcher we can't run any effects.

So, we will still need IO#unsafeRun*. We can use this exactly once to obtain a dispatcher during the setup process, that we can then use for all subsequent requests.

Does that answer your question? Thanks, and PRs welcome for this :)

from feral.

mcanlas avatar mcanlas commented on June 24, 2024 1

Shout out @kamilkloch :)

from feral.

mcanlas avatar mcanlas commented on June 24, 2024

So are you suggesting that with both Feral and my work, we should bootstrap a Dispatcher like a resource for the lifetime of the lambda, and then continually use that Dispatcher for the times when we need to be unsafe?

from feral.

armanbilge avatar armanbilge commented on June 24, 2024

Yes, exactly. It seems to me that an application should never have to call IO.unsafeRun* more than once: instead, it can use that one call to setup a Dispatcher, and use that for all subsequent unsafe calls.

from feral.

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.