-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathReactiveSupport.java
More file actions
55 lines (47 loc) · 1.3 KB
/
ReactiveSupport.java
File metadata and controls
55 lines (47 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;
import io.jooby.internal.handler.ChunkedSubscriber;
import io.jooby.internal.handler.ConcurrentHandler;
/**
* Utility function for handling {@link CompletionStage} and {@link Flow.Publisher}.
*
* @author edgar
* @since 3.0.0
*/
public class ReactiveSupport {
private static final Route.Filter CONCURRENT = new ConcurrentHandler();
private ReactiveSupport() {}
/**
* Creates a subscriber from web context.
*
* @param ctx Web Context.
* @param <T> Flow type.
* @return New subscriber.
*/
public static <T> Flow.Subscriber<T> newSubscriber(Context ctx) {
return new ChunkedSubscriber(ctx);
}
/**
* Concurrent filter. Handle {@link CompletionStage} and {@link Flow} responses.
*
* @return Filter.
*/
public static Route.Filter concurrent() {
return CONCURRENT;
}
/**
* Handler for {@link CompletionStage} and {@link Flow.Publisher} result types.
*
* @param next Next handler in pipeline.
* @return A new wrapped route handler.
*/
public static Route.Handler concurrent(Route.Handler next) {
return CONCURRENT.then(next);
}
}