Giter Site home page Giter Site logo

Comments (6)

wqking avatar wqking commented on May 26, 2024

What problem?

from eventpp.

zhllxt avatar zhllxt commented on May 26, 2024

`#include
#include "eventpp/eventdispatcher.h"
#include "eventpp/mixins/mixinfilter.h"

int main()
{
eventpp::EventDispatcher<int, void ()> dispatcher;

dispatcher.appendListener(3, []()
{
	std::cout << "Got event 31." << std::endl;
});

auto listener = dispatcher.appendListener(3, []()
{
	std::cout << "Got event 32." << std::endl;
});

dispatcher.insertListener(5, []()
{
	std::cout << "Got event 5." << std::endl;
}, listener);

dispatcher.dispatch(3);

// -- the output is :
// Got event 31.
// Got event 5.
// Got event 32.

while (std::getchar() != '\n');

return 0;

}
`

from eventpp.

wqking avatar wqking commented on May 26, 2024

Thanks, I will look into it.

from eventpp.

wqking avatar wqking commented on May 26, 2024

This is not a bug (at least not a serious bug) but needs improvement.
Function insertListener should check and forbid to insert a listener for different event with the one in before handle.
Also seems there should be more unit tests for insertListener.
I will fix this issue.

Currently before the fix, you just need to avoid to insertListener with different event.

from eventpp.

wqking avatar wqking commented on May 26, 2024

I added function ownsHandle to check if the handle belongs the CallbackList or EventDispatcher.
You should call ownsHandle before insertListener if you are not sure if before belongs to the dispatcher.
insertListener doesn't verify the handle for performance reason.

So your sample code will look like,

if(dispatcher.ownsHandle(5, listener)) {
    dispatcher.insertListener(5, []()
    {
        std::cout << "Got event 5." << std::endl;
    }, listener);
}

from eventpp.

zhllxt avatar zhllxt commented on May 26, 2024

Thanks, Nice work.

from eventpp.

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.