Skip to content

Commit ea7eb18

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

File tree

1 file changed

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

1 file changed

+62
-1
lines changed

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

+62-1
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,70 @@ 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+
*/
667+
@Deprecated(forRemoval = true)
668+
public <T> SerializableConsumer<T> accessLater(
669+
SerializableConsumer<T> accessTask,
670+
SerializableRunnable detachHandler) {
671+
return wrapWithAccess(accessTask, detachHandler);
672+
}
673+
674+
/**
675+
* Wraps the given access task as a runnable that runs the given task with
676+
* this UI locked. The wrapped task may be run synchronously or
677+
* asynchronously. If the UI is detached when the returned runnable is run,
678+
* the provided detach handler is run instead. If the provided detach
679+
* handler is <code>null</code>, the returned runnable may throw an
680+
* {@link UIDetachedException}.
681+
* <p>
682+
* This method can be used to create a callback that can be passed to an
683+
* external notifier that isn't aware of the synchronization needed to
684+
* update a UI instance.
685+
*
686+
* @param accessTask
687+
* the task that updates this UI, not <code>null</code>
688+
* @param detachHandler
689+
* the callback that will be invoked if the UI is detached, or
690+
* <code>null</code> as described above
691+
* @return a runnable that will run either the access task or the detach
692+
* handler, possibly asynchronously
693+
*/
694+
public SerializableRunnable wrapWithAccess(SerializableRunnable accessTask,
695+
SerializableRunnable detachHandler) {
635696
Objects.requireNonNull(accessTask, "Access task cannot be null");
636697

637698
return () -> access(accessTask::run, detachHandler);
@@ -657,7 +718,7 @@ public SerializableRunnable accessLater(SerializableRunnable accessTask,
657718
* @return a consumer that will run either the access task or the detach
658719
* handler, possibly asynchronously
659720
*/
660-
public <T> SerializableConsumer<T> accessLater(
721+
public <T> SerializableConsumer<T> wrapWithAccess(
661722
SerializableConsumer<T> accessTask,
662723
SerializableRunnable detachHandler) {
663724
Objects.requireNonNull(accessTask, "Access task cannot be null");

0 commit comments

Comments
 (0)