Skip to content

Commit

Permalink
Add cancellation support to ServiceInvocation
Browse files Browse the repository at this point in the history
Introduced a `cancelled` flag and implemented the `cancel` method to mark invocations as cancelled. Added a new `isCancelled` method to check the cancellation status of an invocation. This allows the client to determine if the application is still interested in the result while still executing the invocation.
  • Loading branch information
dlemmermann committed Nov 7, 2024
1 parent a0792d3 commit 666759f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/com/dlsc/retrofitfx/ServiceInvocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public final class ServiceInvocation<T> implements Worker<T> {

private long delay;

private boolean cancelled;

private ServiceInvocation(String name, ServiceSupplier<T> service) {
this.name = Objects.requireNonNull(name, "service invocation name can not be null");
this.service = Objects.requireNonNull(service, "service can not be null");
Expand Down Expand Up @@ -742,9 +744,26 @@ public ReadOnlyStringProperty titleProperty() {

// cancel

/**
* Marks the invocation as cancelled. Please be aware that the invocation will still execute
* once started. The "cancelled" flag can only be used by the client to check whether the application
* is still interested in the result.
*
* @return always true
*/
@Override
public boolean cancel() {
throw new UnsupportedOperationException();
cancelled = true;
return true;
}

/**
* Returns true if the application has invoked the {@link #cancel} method.
*
* @return true or false depending on whether the invocation has been cancelled or not
*/
public boolean isCancelled() {
return cancelled;
}

/**
Expand Down

0 comments on commit 666759f

Please sign in to comment.