/** * Wraps a runnable so that it is called on the UI thread. * <p> * This is handy if you pass a {@link Runnable} as callback into some async * API * </p> * * @param r * the runnable to wrap * @return a new runnable who invokes the real runnable on the UI thread */ default Runnable wrap(Runnable r) { return () -> asyncExec(r); }
/** * Wraps a bi-consumer so that it is called on the UI thread * <p> * This is handy if you pass a {@link BiConsumer} as callback into some * async API * </p> * * @param c * the consumer to wrap * @return a new consumer who invokes the real consumer on the UI thread */ default <T, U> BiConsumer<T, U> wrap(BiConsumer<T, U> c) { return (t, u) -> asyncExec(() -> c.accept(t, u)); }
/** * Wraps a consumer so that it is called on the sync thread. * <p> * This is handy if you pass a {@link Consumer} as callback into some async * API * </p> * * @param c * the consumer to wrap * @return a new consumer who invokes the real consumer on the UI thread */ default <T> Consumer<T> wrap(Consumer<T> c) { return (t) -> asyncExec(() -> c.accept(t)); }