Giter VIP home page Giter VIP logo

Comments (8)

sebthom avatar sebthom commented on May 28, 2024

I am not familar with the EventEmitter API. Can you provide a minimal self-containing runnable test class?

from haxe-concurrent.

darmie avatar darmie commented on May 28, 2024

Hi @sebthom this is a reproducible class, it works for small test

import buddy.Buddy;

using buddy.Should;
/**
	@author Damilare Akinlaja
**/
class Main implements Buddy<[TestEvent]> {}

class TestEvent extends buddy.BuddySuite {
	public function new() {
		describe("Event emitter test", {
			it("should emit only once", (done) -> {
				final eventEmitter = new EventEmitter();
				eventEmitter.once('start', (values) -> {
					final start = values[0];
					final end = values[1];
					start.should.be(1);
					end.should.be(100);
					done();
				});
				eventEmitter.emit('start', 1, 100);
				eventEmitter.emit('start', 2, 100);
			});
		});
	}
}

But when I use it on a more bigger project and send many events, there is an obvious delay before listeners are triggered.

It fails entirely on C++ target with timeout errors Timeout after 5000 ms in a more complex project with many events.

from haxe-concurrent.

sebthom avatar sebthom commented on May 28, 2024

Hi, the test works fine for me in CPP. But it fails for javascript. The reason seems to be your usage of the rest operator.

Testing with Javascript I get this error:

Event emitter test
  should emit only once (FAILED)
    Expected 100, was null

I guess the reason is your usage of the rest operator with the EventDispatcher#fire method which only declares on argument.
In Javascript if you pass more arguments to a function than it declares, the remaining arguments are silently dropped by the JS runtime. Interestingly tho, it works on all targets except JavaScript, so maybe this is a bug in Haxe's JS transpiler in the context of generics, the haxe.Rest type and the rest operator.

from haxe-concurrent.

darmie avatar darmie commented on May 28, 2024

@sebthom noted! I'll fix that for JavaScript.

I still wonder why I get timeout errors in C++ in my project.

from haxe-concurrent.

sebthom avatar sebthom commented on May 28, 2024

Without having looked into your project. Maybe your are running into race conditions because of multi-threading. I don't think the way you are accessing the maps in the EventEmitter is thread-safe.

from haxe-concurrent.

darmie avatar darmie commented on May 28, 2024

@sebthom any idea how I can solve this problem?

from haxe-concurrent.

sebthom avatar sebthom commented on May 28, 2024

@sebthom any idea how I can solve this problem?

You could try to guard all calls to a map with a dedicated hx.concurrent.RLock instance.

from haxe-concurrent.

stale avatar stale commented on May 28, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

from haxe-concurrent.

Related Issues (17)

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.