When using javafx.concurrent.Task, I often want to perform an action when the Task is completed, regardless of whether it succeeded or failed.
I suggest to add new EventType WORKER_STATE_COMPLETED as the common supertype for WORKER_STATE_SUCCEEDED, WORKER_STATE_FAILED, WORKER_STATE_CANCELLED.
This would allow to write
task.addEventHandler(WORKER_STATE_COMPLETED, e -> handle(e));
instead of
task.addEventHandler(ANY, e -> {
if(e.getEventType() == WORKER_STATE_SUCCEEDED
|| e.getEventType() == WORKER_STATE_FAILED
|| e.getEventType() == WORKER_STATE_CANCELLED) {
handle(e);
}
});
Furthermore, I suggest to add method Worker.State.isCompleted() that reutrns true for SUCCEEDED, FAILED, CANCELLED, and returns false otherwise.
This would allow to write
if(state.isCompleted()) {
doSomething();
}
instead of
switch(state) {
case SUCCEEDED: // fall through
case FAILED: // fall through
case CANCELLED:
doSomething();
break;
default: // do nothing
}
I suggest to add new EventType WORKER_STATE_COMPLETED as the common supertype for WORKER_STATE_SUCCEEDED, WORKER_STATE_FAILED, WORKER_STATE_CANCELLED.
This would allow to write
task.addEventHandler(WORKER_STATE_COMPLETED, e -> handle(e));
instead of
task.addEventHandler(ANY, e -> {
if(e.getEventType() == WORKER_STATE_SUCCEEDED
|| e.getEventType() == WORKER_STATE_FAILED
|| e.getEventType() == WORKER_STATE_CANCELLED) {
handle(e);
}
});
Furthermore, I suggest to add method Worker.State.isCompleted() that reutrns true for SUCCEEDED, FAILED, CANCELLED, and returns false otherwise.
This would allow to write
if(state.isCompleted()) {
doSomething();
}
instead of
switch(state) {
case SUCCEEDED: // fall through
case FAILED: // fall through
case CANCELLED:
doSomething();
break;
default: // do nothing
}