Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🦜 Implement ElasticEvent to allow magic treatment of EventManager#callEvent #29

Open
nuriofernandez opened this issue Jun 22, 2021 · 1 comment

Comments

@nuriofernandez
Copy link
Owner

Implement a way to handle events after his completion open to different implementations.

eventManager.callEvent(new NormalEventExample());

eventManager.callEvent(new ConsumibleEventExample()).onComplete(() -> {
    System.out.println("Event completed callback");
});

String name = eventManager.callEvent(new StringEventReturningExample());
@nuriofernandez
Copy link
Owner Author

Testing class:

import me.nurio.events.EventManager;
import me.nurio.events.ReflectedEventHandler;

public class ElasticEventTest {

    public static void main(String[] args) {
        EventManager eventManager = ReflectedEventHandler.createEventManager();

        eventManager.callEvent(new TestEvent()); // void

        AsyncResponse asyncResponse = eventManager.callEvent(new TestConsumableEvent());

        eventManager.callEvent(new TestConsumableEvent()).onComplete(() -> {}); // void

        String text = eventManager.callEvent(new StringReturnerEvent());
    }


    public static class TestEvent extends Event {}
    public static class TestConsumableEvent extends ConsumableEvent {}
    public static class ConsumableEvent extends ElasticEvent<AsyncResponse> {}
    public static class StringReturnerEvent extends ElasticEvent<String> {}

    interface AsyncResponse {
        void onComplete(AsyncFunction asyncFunction);
    }

    @FunctionalInterface
    interface AsyncFunction {
        void onComplete();
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant