mirror of
https://github.com/SimplexDevelopment/SimplexSS.git
synced 2024-12-22 13:07:37 +00:00
Switch to using Mono.create()
Switched from using Mono.just(T) and Mono.empty() for creating Mono<Void> objects to Mono.create(sink -> {});
This commit is contained in:
parent
43dee08554
commit
c9fa0c1ca0
@ -26,7 +26,6 @@ package io.github.simplexdevelopment.impl;
|
||||
|
||||
import io.github.simplexdevelopment.scheduler.ExecutableService;
|
||||
import io.github.simplexdevelopment.scheduler.ServicePool;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class ServiceImpl extends ExecutableService {
|
||||
@ -39,18 +38,18 @@ public class ServiceImpl extends ExecutableService {
|
||||
|
||||
@Override
|
||||
public Mono<Void> start() {
|
||||
return Mono.just(plugin)
|
||||
.map(JavaPlugin::getLogger)
|
||||
.doOnNext(l -> l.info("The service has executed successfully!"))
|
||||
.then();
|
||||
return Mono.create(sink -> {
|
||||
plugin.getLogger().info("The service has started successfully!");
|
||||
sink.success();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> stop() {
|
||||
return Mono.just(plugin)
|
||||
.map(JavaPlugin::getLogger)
|
||||
.doOnNext(l -> l.info("The service has stopped"))
|
||||
.then();
|
||||
return Mono.create(sink -> {
|
||||
plugin.getLogger().info("The service has stopped successfully!");
|
||||
sink.success();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,9 +181,17 @@ public abstract class ExecutableService implements IService {
|
||||
this.delay = Objects.requireNonNullElse(delay, 0L);
|
||||
this.period = Objects.requireNonNullElse(period, (20L * 60L) * 20L);
|
||||
this.mayInterruptWhenRunning = mayInterruptWhenRunning;
|
||||
|
||||
if (parentPool == null) {
|
||||
this.parentPool = new ServicePool("defaultPool" + SchedulingSystem.denom, false);
|
||||
SchedulingSystem.denom++;
|
||||
} else {
|
||||
this.parentPool = parentPool;
|
||||
}
|
||||
|
||||
this.parentPool.getAssociatedServices().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
@ -245,6 +253,9 @@ public abstract class ExecutableService implements IService {
|
||||
|
||||
@Override
|
||||
public Mono<Void> setParentPool(ServicePool servicePool) {
|
||||
return Mono.just(servicePool).doOnNext(pool -> this.parentPool = pool).then();
|
||||
return Mono.create(sink -> {
|
||||
this.parentPool = servicePool;
|
||||
sink.success();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -102,11 +102,7 @@ public final class SchedulingSystem<T extends JavaPlugin> implements ISchedule {
|
||||
|
||||
@Override
|
||||
public @NotNull Mono<Void> runOnce(IService service) {
|
||||
return Mono.just(service)
|
||||
.doOnNext(s -> s.start()
|
||||
.then(s.stop())
|
||||
.subscribe())
|
||||
.then();
|
||||
return Mono.create(sink -> service.start().then(service.stop()).subscribe(sink::success));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -186,11 +186,13 @@ public final class ServicePool implements Identifier {
|
||||
* @return A {@link Mono<Void>} object which can be used to stop the service.
|
||||
*/
|
||||
public @NotNull Mono<Void> stopService(@NotNull String service_name, @Nullable Mono<Disposable> disposable) {
|
||||
return Mono.create(sink -> {
|
||||
getService(service_name).doOnNext(IService::stop).subscribe();
|
||||
if (disposable != null) {
|
||||
disposable.doOnNext(Disposable::dispose).subscribe();
|
||||
}
|
||||
return Mono.empty();
|
||||
sink.success();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,7 +225,7 @@ public final class ServicePool implements Identifier {
|
||||
*/
|
||||
public @NotNull Mono<ServicePool> recycle() {
|
||||
this.getAssociatedServices().clear();
|
||||
return Mono.just(this);
|
||||
return Mono.create(sink -> sink.success(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user