Coder Social home page Coder Social logo

Comments (3)

danielhasan1 avatar danielhasan1 commented on July 21, 2024

The proposal will solve this issue on a small level, but when the payload size is big and there are multiple consumers who are consuming the dispatched event at the same time this will become a big issue it will block all the memory. Especially for long-running tasks or coroutines.
A quick fix that comes into my mind is writing a wrapper inside dispatch to make the payload a frozen dict.
multiple handlers could accept it, frozen dict won't change. if anyone wants to change any property of that dict they could create a separate copy of that dict or get items from that dict.

from fastapi-events.

melvinkcx avatar melvinkcx commented on July 21, 2024

@danielhasan1 you're right. I haven't tried to address this issue because the payload can technically be of any type, not just dict. Either approach risks breaking the user's code if the payload contains values (custom objects, etc) that cannot be cloned or frozen.

I'm also not aware of any "standard" approach to making a dict immutable as PEP 416 was rejected and PEP 603 is still under drafting stage.

I think it's best we keep this unfixed for now.

from fastapi-events.

ebrahimradi avatar ebrahimradi commented on July 21, 2024

I think it's not about this library, it's about our design. events should be immutable. as a developer you should try design to have immutable events. for example you can try pydantic frozen classes or frozen dataclass or something that guarantee immutable events.
one suggestion is to change library to only accept immutable events data :D

from fastapi-events.

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.