Repeats the operations of provided {@code supplier} infinitely,
until one of the {@code Promise}s completes exceptionally.
496739
@NotNull
	public static Promise<Void> repeat(@NotNull Supplier<Promise<Void>> supplier) {
		return Promise.ofCallback(cb ->
				repeatImpl(supplier, cb));
	}
423191
public static <T, R> Collector<T, ?, R> streaming(final long maxWaitIntervalInMillis, final Supplier<? extends BlockingQueue<T>> queueSupplier,
            final Function<? super Stream<T>, R> streamingCollector) {
        final Function<Stream<T>, ContinuableFuture<R>> streamingCollector2 = new Function<Stream<T>, ContinuableFuture<R>>() {
            @Override
            public ContinuableFuture<R> apply(Stream<T> t) {
                return t.asyncCall(streamingCollector);
            }
        };

        return streaming(queueSupplier, streamingCollector2, maxWaitIntervalInMillis);
    }
1035612
public <R> R wrapClassLoader(Supplier<R> supplier) {
		try (TemporaryClassLoaderContext tmpCl = new TemporaryClassLoaderContext(classLoader)){
			return supplier.get();
		}
	}
356787
@SuppressWarnings("unchecked")
  static Supplier<CompletableFuture<ExecutionResult>> makeAsync(Supplier<CompletableFuture<ExecutionResult>> supplier,
      Scheduler scheduler, FailsafeFuture<Object> future) {
    return () -> {
      CompletableFuture<ExecutionResult> promise = new CompletableFuture<>();
      Callable<Object> callable = () -> supplier.get().handle((result, error) -> {
        // Propagate result
        if (result != null)
          promise.complete(result);
        else
          promise.completeExceptionally(error);
        return result;
      });

      try {
        future.inject((Future) scheduler.schedule(callable, 0, TimeUnit.NANOSECONDS));
      } catch (Exception e) {
        promise.completeExceptionally(e);
      }
      return promise;
    };
  }
1154655
public static <T, E extends Exception> Supplier<T> sneaked(SneakySupplier<T, E> supplier) {
    return () -> {
      @SuppressWarnings("unchecked")
      SneakySupplier<T, RuntimeException> castedSupplier =
          (SneakySupplier<T, RuntimeException>) supplier;
      return castedSupplier.get();
    };
  }
671200
<T> T doExclusive(Supplier<T> supplier) {

        LettuceAssert.notNull(supplier, "Supplier must not be null");

        synchronized (this) {

            try {

                lockWritersExclusive();
                return supplier.get();
            } finally {
                unlockWritersExclusive();
            }
        }
    }
98106
public static <T> Function<Object, T> forSupplier(Supplier<T> supplier) {
		return input -> supplier.get();
	}
41488
public T computeIfAbsent(final Supplier<T> lazy) {
        final T val = get();
        if (val == UNSET)
            return setOnceFromSupplier(lazy);

        return val;

    }
78640
public int locked (@Nonnull final IntSupplier aSupplier)
  {
    ValueEnforcer.notNull (aSupplier, "Supplier");

    lock ();
    try
    {
      return aSupplier.getAsInt ();
    }
    finally
    {
      unlock ();
    }
  }
1184826
private static <T> void acceptResult(CompletableCompletionStage<T> s, Supplier<? extends T> supplier) {
        try {
            // exception can be thrown only by supplier. All callbacks are generated by us and they do not throw any exceptions
            s.complete(supplier.get());
        } catch (Throwable e) {
            handleFailure(s, e);
        }
    }
827067
public static <T> Supplier<T> memoize(final Supplier<T> supplier) {
        return new Supplier<T>() {
            private volatile boolean initialized = false;
            private T instance = null;

            @Override
            public T get() {
                if (initialized == false) {
                    synchronized (this) {
                        if (initialized == false) {
                            instance = supplier.get();
                        }

                    }
                }

                return instance;
            }
        };
    }
1032807
synchronized void result(@Nullable T res) {
        if (isFinished) {
            throw new RuntimeException("Promise " + this + " already completed!");
        }
        isFinished = true;
        result = res;
        deliverResult();
    }
1215438
public static <T> Supplier<T> recover(Supplier<T> supplier, Function<Exception, T> exceptionHandler){
        return () -> {
            try{
                return supplier.get();
            }catch (Exception exception){
                return exceptionHandler.apply(exception);
            }
        };
    }
126338
@SuppressWarnings("unchecked")
    public static <T> Randomizer<T> asRandomizer(final Supplier<T> supplier) {

        class RandomizerProxy implements InvocationHandler {

            private final Supplier<?> target;

            private RandomizerProxy(final Supplier<?> target) {
                this.target = target;
            }

            @Override
            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                if ("getRandomValue".equals(method.getName())) {
                    Method getMethod = target.getClass().getMethod("get");
                    getMethod.setAccessible(true);
                    return getMethod.invoke(target);
                }
                return null;
            }
        }

        return (Randomizer<T>) Proxy.newProxyInstance(
                Randomizer.class.getClassLoader(),
                new Class[]{Randomizer.class},
                new RandomizerProxy(supplier));
    }
202101
public static <A> IO<A> io(Supplier<A> supplier) {
        return new IO<A>() {
            @Override
            public A unsafePerformIO() {
                return supplier.get();
            }

            @Override
            public CompletableFuture<A> unsafePerformAsyncIO(Executor executor) {
                return supplyAsync(supplier, executor);
            }
        };
    }
715081
public static <T> Stream<T> of(final Supplier<Collection<? extends T>> supplier) {
        final Iterator<T> iter = new ObjIteratorEx<T>() {
            private Iterator<? extends T> iterator = null;

            @Override
            public boolean hasNext() {
                if (iterator == null) {
                    init();
                }

                return iterator.hasNext();
            }

            @Override
            public T next() {
                if (iterator == null) {
                    init();
                }

                return iterator.next();
            }

            private void init() {
                final Collection<? extends T> c = supplier.get();

                if (N.isNullOrEmpty(c)) {
                    iterator = ObjIterator.empty();
                } else {
                    iterator = c.iterator();
                }
            }
        };

        return of(iter);
    }
1354774
public static <T, V> ChannelSupplier<V> remap(ChannelSupplier<T> supplier, Function<? super T, ? extends Iterator<? extends V>> fn) {
		return new AbstractChannelSupplier<V>(supplier) {
			Iterator<? extends V> iterator = CollectionUtils.emptyIterator();
			boolean endOfStream;

			@Override
			protected Promise<V> doGet() {
				if (iterator.hasNext()) return Promise.of(iterator.next());
				return Promise.ofCallback(this::next);
			}

			private void next(SettableCallback<V> cb) {
				if (!endOfStream) {
					supplier.get()
							.whenComplete((item, e) -> {
								if (e == null) {
									if (item == null) endOfStream = true;
									iterator = fn.apply(item);
									if (iterator.hasNext()) {
										cb.set(iterator.next());
									} else {
										next(cb);
									}
								} else {
									cb.setException(e);
								}
							});
				} else {
					cb.set(null);
				}
			}
		};
	}