I can't google jargon, what do you call it when you "flip" a function call, such that the call becomes an event in some dispatch system and return becomes a call on the event? I had to implement five such APIs this week with surface level differences and I'm starting to feel like it has to have a name if it's this popular.

For the pedantic, I mean async calls in JS in particular, I know you can't just invert a synchronous function call that uses a stack without peek.

  • 0
    Promise to observable and oposite?
  • 0
    @FallingUpwards I was kinda hoping for something short and unique that I can google to learn about the pattern.
  • 0
    event listeners? (sometimes event handlers)
  • 0
    @lbfalvy I'm not entirely sure about what you mean.

    In general, command pattern as a common category.

    In your specific case, I think you're looking for the word emitter?


    Maybe look at the PSR - I think the definitions are well written, just ignore the PHP part.
  • 0
    I don't think this is quite right but just in case - call backs.
  • 0
    @IntrusionCM Command pattern was close to what I imagined, but I ended up with this weird thing that looks a lot like an in-thread load balancer instead, which ended up solving all my problems at once:

  • 0
    Apparently this is a very universal problem called communication, notable patterns are monads, coroutines, commands. These aren't doing the same thing, but they all serve to blur the line between caller and callee in order to give specific operations much greater access to control flow than a regular function could have.
Add Comment