3

我正在使用 JDK 9 Flow API 创建一个用户事件系统,所以我有一个房间(它扩展了UserSubscriver上面的类),它可能有很多用户,每个用户都可以随时提供(调度)更新。

public abstract class UserSubscriver implements Flow.Subscriber<Notification> {
    private Flow.Subscription subscription;

    @Override
    public void onSubscribe(final Flow.Subscription subscription) {
        this.subscription = subscription;
        subscription.request(1);
    }

    @Override
    public void onError(final Throwable throwable) {
        // ...
    }

    @Override
    public void onNext(final Notification notification) {
        // ...
        subscription.request(1);
    }

    @Override
    public void onComplete() {
        // How can I know who was the publisher of this?
    }
}

用户等级:

public class User extends SubmissionPublisher<Notification> {

    ....

    public int offer(Notification item) {
        return super.offer(item, (sub, msg) -> false);
    }
}

onUpdate我可以接收任何参数,所以我可以接收更新的发布者,但是在onComplete.

我如何知道谁是onComplete活动的发布者?

4

0 回答 0