All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.reactor.event.DefaultAsyncEvent Maven / Gradle / Ivy

The newest version!
package org.zodiac.reactor.event;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;

import java.util.function.Function;

public class DefaultAsyncEvent implements AsyncEvent {

    private transient Mono async = Mono.empty();
    private transient Mono first = Mono.empty();

    private transient boolean hasListener;

    public DefaultAsyncEvent() {
        super();
    }

    public synchronized void async(Publisher publisher) {
        hasListener = true;
        this.async = async.then(AsyncEventHooks.hookAsync(this, Mono.fromDirect(publisher)));
    }

    @Override
    public synchronized void first(Publisher publisher) {
        hasListener = true;
        this.first = AsyncEventHooks.hookFirst(this, Mono.fromDirect(publisher)).then(first);
    }

    @Override
    public synchronized void transformFirst(Function, Publisher> mapper) {
        hasListener = true;
        this.first = Mono.fromDirect(mapper.apply(this.first));
    }

    @Override
    public synchronized void transform(Function, Publisher> mapper) {
        hasListener = true;
        this.async = Mono.fromDirect(mapper.apply(this.async));
    }

    @Override
    public Mono getAsync() {
        return this.first.then(this.async).then();
    }

    public boolean hasListener() {
        return hasListener;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy