use of io.deephaven.web.shared.fu.PromiseLike.CANCELLATION_MESSAGE in project deephaven-core by deephaven.
the class QueryConnectable method startSession.
@JsMethod
public CancellablePromise<IdeSession> startSession(String type) {
JsLog.debug("Starting", type, "console session");
LazyPromise<Ticket> promise = new LazyPromise<>();
final ClientConfiguration config = connection.get().getConfig();
final Ticket ticket = new Ticket();
ticket.setTicket(config.newTicketRaw());
final JsRunnable closer = () -> {
boolean run = !cancelled.has(ticket);
if (run) {
cancelled.add(ticket);
connection.get().releaseTicket(ticket);
}
};
onConnected().then(e -> Callbacks.grpcUnaryPromise(callback -> {
StartConsoleRequest request = new StartConsoleRequest();
request.setSessionType(type);
request.setResultId(ticket);
connection.get().consoleServiceClient().startConsole(request, connection.get().metadata(), callback::apply);
})).then(result -> {
promise.succeed(ticket);
return null;
}, error -> {
promise.fail(error);
return null;
});
return promise.asPromise(result -> {
if (cancelled.has(ticket)) {
// a bit hacky, but it works...
throw new RuntimeException(CANCELLATION_MESSAGE);
}
final IdeSession session = new IdeSession(connection.get(), result, closer);
sessions.add(session);
return session;
}, closer);
}
Aggregations