-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSyncTask.java
81 lines (72 loc) · 1.94 KB
/
SyncTask.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package org.vaadin.flow.helper;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.server.Command;
import java.util.concurrent.ExecutionException;
/**
* Created by Artem Godin on 3/29/2019.
*/
public class SyncTask extends Task {
/**
* Create a new task
*
* @param asyncManager
*/
SyncTask(AsyncManager asyncManager) {
super(asyncManager);
}
/**
* Perform command in UI context.
*
* @param command Command to run
*/
public void push(Command command) {
command.execute();
}
/**
* Cancel and unregister the task.
*/
public void cancel() {
// no-op
}
/**
* Wait for the task to finish.
*
* @throws ExecutionException
* @throws InterruptedException
*/
public void await() throws ExecutionException, InterruptedException {
// no-op
}
/**
* Allow worker thread to be interrupted when UI or Component detaches. Default behaviour.
*/
public void allowThreadInterrupt() {
// no-op
}
/**
* Prevent worker thread interruption when UI or Component detaches.
*/
public void preventThreadInterrupt() {
// no-op
}
/**
* Register action
*
* @param ui UI owning current view
* @param component
* @param action Action
*/
void register(UI ui, Component component, Action action) {
setUI(ui);
try {
getAsyncManager().handleTaskStateChanged(this, AsyncManager.TaskStateHandler.State.RUNNING);
action.run(this);
getAsyncManager().handleTaskStateChanged(this, AsyncManager.TaskStateHandler.State.DONE);
} catch (Exception e) {
// Dump
getAsyncManager().handleException(this, e);
getAsyncManager().handleTaskStateChanged(this, AsyncManager.TaskStateHandler.State.DONE);
}
}
}