Skip to content

Commit

Permalink
fix: Deprecate accessLater in favor of wrapWithAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- committed Feb 6, 2025
1 parent feac410 commit ea7eb18
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion flow-server/src/main/java/com/vaadin/flow/component/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,70 @@ public void handleError(Exception exception) {
* <code>null</code> as described above
* @return a runnable that will run either the access task or the detach
* handler, possibly asynchronously
* @deprecated Use
* {@link #wrapWithAccess(SerializableRunnable, SerializableRunnable)}
* instead which is a better name for the method
*
*/
@Deprecated(forRemoval = true)
public SerializableRunnable accessLater(SerializableRunnable accessTask,
SerializableRunnable detachHandler) {
return wrapWithAccess(accessTask, detachHandler);
}

/**
* Wraps the given access task as a consumer that passes a value to the
* given task with this UI locked. The wrapped task may be run synchronously
* or asynchronously. If the UI is detached when the returned consumer is
* run, the provided detach handler is run instead. If the provided detach
* handler is <code>null</code>, the returned runnable may throw an
* {@link UIDetachedException}.
* <p>
* This method can be used to create a callback that can be passed to an
* external notifier that isn't aware of the synchronization needed to
* update a UI instance.
*
* @param accessTask
* the task that updates this UI, not <code>null</code>
* @param detachHandler
* the callback that will be invoked if the UI is detached, or
* <code>null</code> as described above
* @return a consumer that will run either the access task or the detach
* handler, possibly asynchronously
* @deprecated Use
* {@link #wrapWithAccess(SerializableConsumer, SerializableRunnable)
* instead which is a better name for the method
*
*/
@Deprecated(forRemoval = true)
public <T> SerializableConsumer<T> accessLater(
SerializableConsumer<T> accessTask,
SerializableRunnable detachHandler) {
return wrapWithAccess(accessTask, detachHandler);
}

/**
* Wraps the given access task as a runnable that runs the given task with
* this UI locked. The wrapped task may be run synchronously or
* asynchronously. If the UI is detached when the returned runnable is run,
* the provided detach handler is run instead. If the provided detach
* handler is <code>null</code>, the returned runnable may throw an
* {@link UIDetachedException}.
* <p>
* This method can be used to create a callback that can be passed to an
* external notifier that isn't aware of the synchronization needed to
* update a UI instance.
*
* @param accessTask
* the task that updates this UI, not <code>null</code>
* @param detachHandler
* the callback that will be invoked if the UI is detached, or
* <code>null</code> as described above
* @return a runnable that will run either the access task or the detach
* handler, possibly asynchronously
*/
public SerializableRunnable wrapWithAccess(SerializableRunnable accessTask,
SerializableRunnable detachHandler) {
Objects.requireNonNull(accessTask, "Access task cannot be null");

return () -> access(accessTask::run, detachHandler);
Expand All @@ -657,7 +718,7 @@ public SerializableRunnable accessLater(SerializableRunnable accessTask,
* @return a consumer that will run either the access task or the detach
* handler, possibly asynchronously
*/
public <T> SerializableConsumer<T> accessLater(
public <T> SerializableConsumer<T> wrapWithAccess(
SerializableConsumer<T> accessTask,
SerializableRunnable detachHandler) {
Objects.requireNonNull(accessTask, "Access task cannot be null");
Expand Down

0 comments on commit ea7eb18

Please sign in to comment.