Skip to content

Commit fb46f04

Browse files
committed
异步事件增加优先级
1 parent 13c01cb commit fb46f04

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

hsweb-core/src/main/java/org/hswebframework/web/event/AsyncEvent.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public interface AsyncEvent {
2121
*/
2222
void async(Publisher<?> publisher);
2323

24+
/**
25+
* 注册一个优先级高的任务
26+
* @param publisher 任务
27+
*/
28+
void first(Publisher<?> publisher);
29+
2430
/**
2531
* 推送事件到 ApplicationEventPublisher
2632
*

hsweb-core/src/main/java/org/hswebframework/web/event/DefaultAsyncEvent.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class DefaultAsyncEvent implements AsyncEvent {
99

1010
@Getter
1111
private Mono<Void> async = Mono.empty();
12+
@Getter
13+
private Mono<Void> first = Mono.empty();
1214

1315
private boolean hasListener;
1416

@@ -17,12 +19,18 @@ public synchronized void async(Publisher<?> publisher) {
1719
this.async = async.then(Mono.from(publisher).then());
1820
}
1921

22+
@Override
23+
public synchronized void first(Publisher<?> publisher) {
24+
hasListener = true;
25+
this.first = Mono.from(publisher).then(first);
26+
}
27+
2028
@Override
2129
public Mono<Void> publish(ApplicationEventPublisher eventPublisher) {
2230

2331
eventPublisher.publishEvent(this);
2432

25-
return this.async;
33+
return this.first.then(this.async);
2634
}
2735

2836
public boolean hasListener() {

0 commit comments

Comments
 (0)