Search in sources :

Example 1 with LazyPromise

use of io.deephaven.web.client.fu.LazyPromise in project deephaven-core by deephaven.

the class IdeSession method runCode.

public CancellablePromise<JsCommandResult> runCode(String code) {
    LazyPromise<JsCommandResult> promise = new LazyPromise<>();
    ExecuteCommandRequest request = new ExecuteCommandRequest();
    request.setConsoleId(this.result);
    request.setCode(code);
    Promise<ExecuteCommandResponse> runCodePromise = Callbacks.grpcUnaryPromise(c -> {
        connection.consoleServiceClient().executeCommand(request, connection.metadata(), c::apply);
    });
    runCodePromise.then(response -> {
        JsVariableChanges changes = JsVariableChanges.from(response.getChanges());
        promise.succeed(new JsCommandResult(changes, response.getErrorMessage()));
        return null;
    }, err -> {
        promise.fail(err);
        return null;
    });
    CancellablePromise<JsCommandResult> result = promise.asPromise(() -> {
        // connection.consoleServiceClient().cancelCommand(cancelRequest, connection.metadata());
        throw new UnsupportedOperationException("cancelCommand");
    });
    CommandInfo commandInfo = new CommandInfo(code, result);
    final CustomEventInit event = CustomEventInit.create();
    event.setDetail(commandInfo);
    fireEvent(IdeSession.EVENT_COMMANDSTARTED, event);
    return result;
}
Also used : JsCommandResult(io.deephaven.web.client.api.console.JsCommandResult) LazyPromise(io.deephaven.web.client.fu.LazyPromise) CustomEventInit(elemental2.dom.CustomEventInit) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges)

Example 2 with LazyPromise

use of io.deephaven.web.client.fu.LazyPromise in project deephaven-core by deephaven.

the class JsTable method getInternalViewportData.

public Promise<TableData> getInternalViewportData() {
    final LazyPromise<TableData> promise = new LazyPromise<>();
    final ClientTableState active = state();
    active.onRunning(state -> {
        if (currentViewportData == null) {
            // no viewport data received yet; let's setup a one-shot UPDATED event listener
            addEventListenerOneShot(EVENT_UPDATED, ignored -> promise.succeed(currentViewportData));
        } else {
            promise.succeed(currentViewportData);
        }
    }, promise::fail, () -> promise.fail("Table closed before viewport data was read"));
    return promise.asPromise(MAX_BATCH_TIME);
}
Also used : ClientTableState(io.deephaven.web.client.state.ClientTableState) LazyPromise(io.deephaven.web.client.fu.LazyPromise)

Example 3 with LazyPromise

use of io.deephaven.web.client.fu.LazyPromise in project deephaven-core by deephaven.

the class JsTable method copy.

@JsMethod
public Promise<JsTable> copy(boolean resolved) {
    if (resolved) {
        LazyPromise<ClientTableState> promise = new LazyPromise<>();
        final ClientTableState unresolved = state();
        unresolved.onRunning(promise::succeed, promise::fail, () -> promise.fail("Table failed or closed, copy could not complete"));
        return promise.asPromise(MAX_BATCH_TIME).then(s -> Promise.resolve(new JsTable(this)));
    }
    return Promise.resolve(new JsTable(this));
}
Also used : ClientTableState(io.deephaven.web.client.state.ClientTableState) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsMethod(jsinterop.annotations.JsMethod)

Example 4 with LazyPromise

use of io.deephaven.web.client.fu.LazyPromise 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);
}
Also used : JsRunnable(io.deephaven.web.shared.fu.JsRunnable) RemoverFn(io.deephaven.web.shared.fu.RemoverFn) JsMethod(jsinterop.annotations.JsMethod) Promise(elemental2.promise.Promise) ConnectToken(io.deephaven.web.shared.data.ConnectToken) JsPropertyMap(jsinterop.base.JsPropertyMap) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) JsProperty(jsinterop.annotations.JsProperty) CANCELLATION_MESSAGE(io.deephaven.web.shared.fu.PromiseLike.CANCELLATION_MESSAGE) ResponseStreamWrapper(io.deephaven.web.client.api.barrage.stream.ResponseStreamWrapper) StartConsoleRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsLog(io.deephaven.web.client.fu.JsLog) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) DomGlobal(elemental2.dom.DomGlobal) GetConsoleTypesRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesRequest) CustomEventInit(elemental2.dom.CustomEventInit) IdeSession(io.deephaven.ide.shared.IdeSession) JsArray(elemental2.core.JsArray) JsSet(elemental2.core.JsSet) LogItem(io.deephaven.web.shared.data.LogItem) JsIgnore(jsinterop.annotations.JsIgnore) List(java.util.List) GetConsoleTypesResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesResponse) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) IdeSession(io.deephaven.ide.shared.IdeSession) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) StartConsoleRequest(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsMethod(jsinterop.annotations.JsMethod)

Example 5 with LazyPromise

use of io.deephaven.web.client.fu.LazyPromise in project deephaven-core by deephaven.

the class IdeSession method getVariableDefinition.

private Promise<JsVariableDefinition> getVariableDefinition(String name, String type) {
    LazyPromise<JsVariableDefinition> promise = new LazyPromise<>();
    final class Listener implements Consumer<JsVariableChanges> {

        final JsRunnable subscription;

        Listener() {
            subscription = subscribeToFieldUpdates(this::accept);
        }

        @Override
        public void accept(JsVariableChanges changes) {
            JsVariableDefinition foundField = changes.getCreated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
            if (foundField == null) {
                foundField = changes.getUpdated().find((field, p1, p2) -> field.getTitle().equals(name) && field.getType().equals(type));
            }
            if (foundField != null) {
                subscription.run();
                promise.succeed(foundField);
            }
        }
    }
    Listener listener = new Listener();
    return promise.timeout(10_000).asPromise().then(Promise::resolve, fail -> {
        listener.subscription.run();
        // noinspection unchecked, rawtypes
        return (Promise<JsVariableDefinition>) (Promise) Promise.reject(fail);
    });
}
Also used : JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsOptional(jsinterop.annotations.JsOptional) JsCommandResult(io.deephaven.web.client.api.console.JsCommandResult) JsFigure(io.deephaven.web.client.api.widget.plot.JsFigure) HashMap(java.util.HashMap) Promise(elemental2.promise.Promise) BiDiStream(io.deephaven.web.client.api.barrage.stream.BiDiStream) JsPropertyMap(jsinterop.base.JsPropertyMap) Supplier(java.util.function.Supplier) Any(jsinterop.base.Any) EVENT_TABLE_OPENED(io.deephaven.web.client.api.QueryConnectable.EVENT_TABLE_OPENED) Js(jsinterop.base.Js) JsArrayLike(jsinterop.base.JsArrayLike) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges) Map(java.util.Map) io.deephaven.web.client.api(io.deephaven.web.client.api) io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb) JsType(jsinterop.annotations.JsType) LazyPromise(io.deephaven.web.client.fu.LazyPromise) ExecutionHandle(io.deephaven.web.shared.ide.ExecutionHandle) JsLog(io.deephaven.web.client.fu.JsLog) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) Ticket(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket) CustomEventInit(elemental2.dom.CustomEventInit) TextDocumentContentChangeEvent(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.changedocumentrequest.TextDocumentContentChangeEvent) JsArray(elemental2.core.JsArray) JsSet(elemental2.core.JsSet) Consumer(java.util.function.Consumer) LogItem(io.deephaven.web.shared.data.LogItem) JsIgnore(jsinterop.annotations.JsIgnore) JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) Timer(com.google.gwt.user.client.Timer) Promise(elemental2.promise.Promise) LazyPromise(io.deephaven.web.client.fu.LazyPromise) CancellablePromise(io.deephaven.web.client.fu.CancellablePromise) JsRunnable(io.deephaven.web.shared.fu.JsRunnable) JsConsumer(io.deephaven.web.shared.fu.JsConsumer) Consumer(java.util.function.Consumer) JsVariableDefinition(io.deephaven.web.client.api.console.JsVariableDefinition) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsVariableChanges(io.deephaven.web.client.api.console.JsVariableChanges)

Aggregations

LazyPromise (io.deephaven.web.client.fu.LazyPromise)6 CustomEventInit (elemental2.dom.CustomEventInit)4 JsArray (elemental2.core.JsArray)3 Promise (elemental2.promise.Promise)3 JsLog (io.deephaven.web.client.fu.JsLog)3 JsConsumer (io.deephaven.web.shared.fu.JsConsumer)3 JsRunnable (io.deephaven.web.shared.fu.JsRunnable)3 JsPropertyMap (jsinterop.base.JsPropertyMap)3 JsSet (elemental2.core.JsSet)2 DomGlobal (elemental2.dom.DomGlobal)2 Ticket (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.ticket_pb.Ticket)2 JsCommandResult (io.deephaven.web.client.api.console.JsCommandResult)2 JsVariableChanges (io.deephaven.web.client.api.console.JsVariableChanges)2 ClientTableState (io.deephaven.web.client.state.ClientTableState)2 JsMethod (jsinterop.annotations.JsMethod)2 JsOptional (jsinterop.annotations.JsOptional)2 Js (jsinterop.base.Js)2 Timer (com.google.gwt.user.client.Timer)1 Global (elemental2.core.Global)1 ThenOnFulfilledCallbackFn (elemental2.promise.IThenable.ThenOnFulfilledCallbackFn)1