Search in sources :

Example 1 with RequestBatcher

use of io.deephaven.web.client.api.batch.RequestBatcher in project deephaven-core by deephaven.

the class JsTable method batch.

@JsMethod
public Promise<JsTable> batch(JsConsumer<RequestBatcher> userCode) {
    boolean rootBatch = batchDepth++ == 0;
    RequestBatcher batcher = workerConnection.getBatcher(this);
    if (!rootBatch) {
        batcher.finishOp();
    }
    userCode.apply(batcher);
    if (--batchDepth == 0) {
        return batcher.sendRequest().then(ignored -> Promise.resolve(JsTable.this));
    } else {
        return batcher.nestedPromise(this);
    }
}
Also used : RequestBatcher(io.deephaven.web.client.api.batch.RequestBatcher) JsMethod(jsinterop.annotations.JsMethod)

Example 2 with RequestBatcher

use of io.deephaven.web.client.api.batch.RequestBatcher in project deephaven-core by deephaven.

the class WorkerConnection method getBatcher.

public RequestBatcher getBatcher(JsTable table) {
    // LATER: consider a global client.batch(()=>{}) method which causes all table statements to be batched
    // together.
    // We will build this architecture to support this, without wiring it up just yet
    RequestBatcher batcher = batchers.get(table);
    if (batcher == null || batcher.isSent()) {
        final RequestBatcher myBatcher = new RequestBatcher(table, this);
        batchers.set(table, myBatcher);
        myBatcher.onSend(r -> {
            // clear out our map references if we're the last batcher to finish running for the given table.
            if (batchers.get(table) == myBatcher) {
                batchers.delete(table);
            }
        });
        return myBatcher;
    }
    return batcher;
}
Also used : RequestBatcher(io.deephaven.web.client.api.batch.RequestBatcher)

Aggregations

RequestBatcher (io.deephaven.web.client.api.batch.RequestBatcher)2 JsMethod (jsinterop.annotations.JsMethod)1