Giter Site home page Giter Site logo

Synchronous Hooks about hookable HOT 4 CLOSED

abarke avatar abarke commented on June 19, 2024
Synchronous Hooks

from hookable.

Comments (4)

Vinccool96 avatar Vinccool96 commented on June 19, 2024 3

If you're the one that added hookable as a dependency I created a package that is the same thing but only uses sync functions

from hookable.

pi0 avatar pi0 commented on June 19, 2024 1

Event Emitter is probably the closest (and best-optimized solution performance-wise - next to plain functions) for the sync method. sync-hookable also seems a good option thanks @Vinccool96!

Here are the options in summary:

from hookable.

pi0 avatar pi0 commented on June 19, 2024

All hookable internals are asynchronous. There are only interceptors you can add and are sync.

By the current code, I would use two simple callback options instead but if you can give more context of your project and usage can help better me understanding.

from hookable.

abarke avatar abarke commented on June 19, 2024

We are using the RxJS WebSocketSubject to handle asynchronous messages. However the serializer and deserializer in WebSocketSubjectConfig are synchronous functions. We added the hooks and it works fine, but we wanted to find out if we could make the hooks synchronous. Similar to how we call the other hooks with:

await hooks.callHook(Hook.SOME_HOOK, data)`. 

We currently just use these hooks for logging, so that works fine, however we were wondering if we can intercept the message using a hook to transform the incoming msg similar to a middleware pattern e.g.

function serializer(msg: Message): WebSocketMessage {
  const transformedMsg = hooks.callHookSync(Hook.BEFORE_SERIALIZED, msg)
  const serialized = serialize(transformedMsg)
  return hooks.callHookSync(Hook.SERIALIZED, serialized)
}

from hookable.

Related Issues (19)

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.