Java Code Examples for io.reactivex.rxjava3.core.Single#just()

The following examples show how to use io.reactivex.rxjava3.core.Single#just() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultShardManager.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public void start() {
    if(started) {
        throw new IllegalStateException("Shard manager is already started!");
    } else {
        started = true;
        catnip().logAdapter().debug("Started DefaultShardManager.");
    }
    
    consumers.add(catnip().dispatchManager().<GatewayClosed>createConsumer(Raw.GATEWAY_WEBSOCKET_CLOSED).handler(gatewayClosed -> {
        catnip().logAdapter().info("Shard {} closed, re-queuing...", gatewayClosed.shardInfo().getId());
        addToConnectQueue(gatewayClosed.shardInfo().getId());
    }));
    
    final Single<GatewayInfo> gatewayInfoCompletableFuture;
    if(catnip().gatewayInfo() != null) {
        // If we already have gateway info, eg. from validating the token,
        // then don't bother fetching it a second time
        //noinspection ConstantConditions
        gatewayInfoCompletableFuture = Single.just(catnip().gatewayInfo());
    } else {
        gatewayInfoCompletableFuture = catnip().rest().user().getGatewayBot();
    }
    
    gatewayInfoCompletableFuture.subscribe(this::checkGatewayInfo,
            e -> {
                throw new IllegalStateException("Couldn't load gateway info!", e);
            });
}
 
Example 2
Source File: MemoryEntityCache.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected <I, T> Single<T> or(final I id, final T data, final T def) {
    if(data == null && def == null) {
        return Single.error(new IllegalArgumentException("No entity for: " + id));
    } else {
        return Single.just(Objects.requireNonNullElse(data, def));
    }
}
 
Example 3
Source File: MemoryEntityCache.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected <I, T> Single<T> or(final I id, final T data) {
    if(data == null) {
        return Single.error(new IllegalArgumentException("No entity for: " + id));
    } else {
        return Single.just(data);
    }
}