/** * Assign a single newly created {@link VirtualTimeScheduler} to all {@link reactor.core.scheduler.Schedulers.Factory} * factories. While the method is thread safe, its usually advised to execute such * wide-impact BEFORE all tested code runs (setup etc). The created scheduler is returned. * * @return the VirtualTimeScheduler that was created and set through the factory */ public static VirtualTimeScheduler getOrSet() { return enable(VirtualTimeScheduler::new, false); }
/** * Common method to enable a {@link VirtualTimeScheduler} in {@link Schedulers} * factories. The supplier is lazily called. Enabling the same scheduler twice is * also idempotent. * * @param schedulerSupplier the supplier executed to obtain a fresh {@link VirtualTimeScheduler} * @return the scheduler that is actually used after the operation. */ static VirtualTimeScheduler enable(Supplier<VirtualTimeScheduler> schedulerSupplier) { return enable(schedulerSupplier, false); }
/** * Assign an externally created {@link VirtualTimeScheduler} to the relevant * {@link reactor.core.scheduler.Schedulers.Factory} factories, depending on how it was created (see * {@link #create()} and {@link #create()}). Contrary to * {@link #getOrSet(VirtualTimeScheduler)}, the provided scheduler is always used, even * if a matching scheduler is currently enabled. * <p> * While the method is thread safe, it's usually advised to execute such wide-impact * BEFORE all tested code runs (setup etc). * * @param scheduler the {@link VirtualTimeScheduler} to use in factories. * @return the enabled VirtualTimeScheduler (same as provided), for chaining */ public static VirtualTimeScheduler set(VirtualTimeScheduler scheduler) { return enable(() -> scheduler, true); }
/** * Assign an externally created {@link VirtualTimeScheduler} to the relevant * {@link reactor.core.scheduler.Schedulers.Factory} factories, depending on how it was created (see * {@link #create()} and {@link #create()}). Note that the returned scheduler * should always be captured and used going forward, as the provided scheduler can be * superseded by a matching scheduler that has already been enabled. * <p> * While the method is thread safe, it's usually advised to execute such wide-impact * BEFORE all tested code runs (setup etc). The actual enabled Scheduler is returned. * * @param scheduler the {@link VirtualTimeScheduler} to use in factories. * @return the enabled VirtualTimeScheduler (can be different from the provided one) */ public static VirtualTimeScheduler getOrSet(VirtualTimeScheduler scheduler) { return enable(() -> scheduler, false); }
/** * Common method to enable a {@link VirtualTimeScheduler} in {@link Schedulers} * factories. The supplier is lazily called. Enabling the same scheduler twice is * also idempotent. * * @param schedulerSupplier the supplier executed to obtain a fresh {@link VirtualTimeScheduler} * @return the scheduler that is actually used after the operation. */ static VirtualTimeScheduler enable(Supplier<VirtualTimeScheduler> schedulerSupplier) { return enable(schedulerSupplier, false); }
/** * Assign a single newly created {@link VirtualTimeScheduler} to all {@link reactor.core.scheduler.Schedulers.Factory} * factories. While the method is thread safe, its usually advised to execute such * wide-impact BEFORE all tested code runs (setup etc). The created scheduler is returned. * * @return the VirtualTimeScheduler that was created and set through the factory */ public static VirtualTimeScheduler getOrSet() { return enable(VirtualTimeScheduler::new, false); }
/** * Assign an externally created {@link VirtualTimeScheduler} to the relevant * {@link reactor.core.scheduler.Schedulers.Factory} factories, depending on how it was created (see * {@link #create()} and {@link #create()}). Note that the returned scheduler * should always be captured and used going forward, as the provided scheduler can be * superseded by a matching scheduler that has already been enabled. * <p> * While the method is thread safe, it's usually advised to execute such wide-impact * BEFORE all tested code runs (setup etc). The actual enabled Scheduler is returned. * * @param scheduler the {@link VirtualTimeScheduler} to use in factories. * @return the enabled VirtualTimeScheduler (can be different from the provided one) */ public static VirtualTimeScheduler getOrSet(VirtualTimeScheduler scheduler) { return enable(() -> scheduler, false); }
/** * Assign an externally created {@link VirtualTimeScheduler} to the relevant * {@link reactor.core.scheduler.Schedulers.Factory} factories, depending on how it was created (see * {@link #create()} and {@link #create()}). Contrary to * {@link #getOrSet(VirtualTimeScheduler)}, the provided scheduler is always used, even * if a matching scheduler is currently enabled. * <p> * While the method is thread safe, it's usually advised to execute such wide-impact * BEFORE all tested code runs (setup etc). * * @param scheduler the {@link VirtualTimeScheduler} to use in factories. * @return the enabled VirtualTimeScheduler (same as provided), for chaining */ public static VirtualTimeScheduler set(VirtualTimeScheduler scheduler) { return enable(() -> scheduler, true); }