Skip to content

Commit ce51b35

Browse files
committed
fix: Deprecate accessLater in favor of wrapWithAccess
1 parent feac410 commit ce51b35

File tree

1 file changed

+61
-1
lines changed
  • flow-server/src/main/java/com/vaadin/flow/component

1 file changed

+61
-1
lines changed

flow-server/src/main/java/com/vaadin/flow/component/UI.java

+61-1
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,69 @@ public void handleError(Exception exception) {
629629
* <code>null</code> as described above
630630
* @return a runnable that will run either the access task or the detach
631631
* handler, possibly asynchronously
632+
* @deprecated Use
633+
* {@link #wrapWithAccess(SerializableRunnable, SerializableRunnable)}
634+
* instead which is a better name for the method
635+
*
632636
*/
637+
@Deprecated(forRemoval = true)
633638
public SerializableRunnable accessLater(SerializableRunnable accessTask,
634639
SerializableRunnable detachHandler) {
640+
return wrapWithAccess(accessTask, detachHandler);
641+
}
642+
643+
/**
644+
* Wraps the given access task as a consumer that passes a value to the
645+
* given task with this UI locked. The wrapped task may be run synchronously
646+
* or asynchronously. If the UI is detached when the returned consumer is
647+
* run, the provided detach handler is run instead. If the provided detach
648+
* handler is <code>null</code>, the returned runnable may throw an
649+
* {@link UIDetachedException}.
650+
* <p>
651+
* This method can be used to create a callback that can be passed to an
652+
* external notifier that isn't aware of the synchronization needed to
653+
* update a UI instance.
654+
*
655+
* @param accessTask
656+
* the task that updates this UI, not <code>null</code>
657+
* @param detachHandler
658+
* the callback that will be invoked if the UI is detached, or
659+
* <code>null</code> as described above
660+
* @return a consumer that will run either the access task or the detach
661+
* handler, possibly asynchronously
662+
* @deprecated Use
663+
* {@link #wrapWithAccess(SerializableConsumer, SerializableRunnable)}
664+
* instead which is a better name for the method
665+
*/
666+
@Deprecated(forRemoval = true)
667+
public <T> SerializableConsumer<T> accessLater(
668+
SerializableConsumer<T> accessTask,
669+
SerializableRunnable detachHandler) {
670+
return wrapWithAccess(accessTask, detachHandler);
671+
}
672+
673+
/**
674+
* Wraps the given access task as a runnable that runs the given task with
675+
* this UI locked. The wrapped task may be run synchronously or
676+
* asynchronously. If the UI is detached when the returned runnable is run,
677+
* the provided detach handler is run instead. If the provided detach
678+
* handler is <code>null</code>, the returned runnable may throw an
679+
* {@link UIDetachedException}.
680+
* <p>
681+
* This method can be used to create a callback that can be passed to an
682+
* external notifier that isn't aware of the synchronization needed to
683+
* update a UI instance.
684+
*
685+
* @param accessTask
686+
* the task that updates this UI, not <code>null</code>
687+
* @param detachHandler
688+
* the callback that will be invoked if the UI is detached, or
689+
* <code>null</code> as described above
690+
* @return a runnable that will run either the access task or the detach
691+
* handler, possibly asynchronously
692+
*/
693+
public SerializableRunnable wrapWithAccess(SerializableRunnable accessTask,
694+
SerializableRunnable detachHandler) {
635695
Objects.requireNonNull(accessTask, "Access task cannot be null");
636696

637697
return () -> access(accessTask::run, detachHandler);
@@ -657,7 +717,7 @@ public SerializableRunnable accessLater(SerializableRunnable accessTask,
657717
* @return a consumer that will run either the access task or the detach
658718
* handler, possibly asynchronously
659719
*/
660-
public <T> SerializableConsumer<T> accessLater(
720+
public <T> SerializableConsumer<T> wrapWithAccess(
661721
SerializableConsumer<T> accessTask,
662722
SerializableRunnable detachHandler) {
663723
Objects.requireNonNull(accessTask, "Access task cannot be null");

0 commit comments

Comments
 (0)