packages/grpc-native-core/src/client_interceptors.js
function _startBatchIfReady(call, batch, batch_state, callback) {
  var completed_ops = batch_state.completed_ops;
  var deferred_batches = batch_state.deferred_batches;
  var batch_ops = Object.keys(batch).map(Number);
  if (_areBatchRequirementsMet(batch_ops, completed_ops)) {
    // Dependencies are met, start the batch and any deferred batches whose
    // dependencies are met as a result.
    call.startBatch(batch, callback);
    completed_ops = Array.from(new Set(completed_ops.concat(batch_ops)));
    deferred_batches = common.flatMap(deferred_batches, function(deferred_batch) {
      var deferred_batch_ops = Object.keys(deferred_batch).map(Number);
      if (_areBatchRequirementsMet(deferred_batch_ops, completed_ops)) {
        call.startBatch(deferred_batch.batch, deferred_batch.callback);
        return [];
      }
      return [deferred_batch];
    });
  } else {
    // Dependencies are not met, defer the batch
    deferred_batches = deferred_batches.concat({
      batch: batch,
      callback: callback
    });
  }
  return {
    completed_ops: completed_ops,
    deferred_batches: deferred_batches
  };
}
function _startBatchIfReady(call, batch, batch_state, callback) {
  var completed_ops = batch_state.completed_ops;
  var deferred_batches = batch_state.deferred_batches;
  var batch_ops = Object.keys(batch).map(Number);
  if (_areBatchRequirementsMet(batch_ops, completed_ops)) {
    // Dependencies are met, start the batch and any deferred batches whose
    // dependencies are met as a result.
    call.startBatch(batch, callback);
    completed_ops = Array.from(new Set(completed_ops.concat(batch_ops)));
    deferred_batches = common.flatMap(deferred_batches, function(deferred_batch) {
      var deferred_batch_ops = Object.keys(deferred_batch).map(Number);
      if (_areBatchRequirementsMet(deferred_batch_ops, completed_ops)) {
        call.startBatch(deferred_batch.batch, deferred_batch.callback);
        return [];
      }
      return [deferred_batch];
    });
  } else {
    // Dependencies are not met, defer the batch
    deferred_batches = deferred_batches.concat({
      batch: batch,
      callback: callback
    });
  }
  return {
    completed_ops: completed_ops,
    deferred_batches: deferred_batches
  };
}
function _startBatchIfReady ( call , batch , batch_state , callback ) { var completed_ops = batch_state . completed_ops ; var deferred_batches = batch_state . deferred_batches ; var batch_ops = Object . keys ( batch ) . map ( Number ) ; if ( _areBatchRequirementsMet ( batch_ops , completed_ops ) ) { // Dependencies are met, start the batch and any deferred batches whose // dependencies are met as a result. call . startBatch ( batch , callback ) ; completed_ops = Array . from ( new Set ( completed_ops . concat ( batch_ops ) ) ) ; deferred_batches = common . flatMap ( deferred_batches , function ( deferred_batch ) { var deferred_batch_ops = Object . keys ( deferred_batch ) . map ( Number ) ; if ( _areBatchRequirementsMet ( deferred_batch_ops , completed_ops ) ) { call . startBatch ( deferred_batch . batch , deferred_batch . callback ) ; return [ ] ; } return [ deferred_batch ] ; } ) ; } else { // Dependencies are not met, defer the batch deferred_batches = deferred_batches . concat ( { batch : batch , callback : callback } ) ; } return { completed_ops : completed_ops , deferred_batches : deferred_batches } ; }
Enforces the order of operations for synchronous requests. If a batch's
operations cannot be started because required operations have not started
yet, the batch is deferred until requirements are met.
@private
@param {grpc.Client~Call} call
@param {object} batch
@param {object} batch_state
@param {number[]} [batch_state.completed_ops] The ops already sent.
@param {object} [batch_state.deferred_batches] Batches to be sent after
their dependencies are fulfilled.
@param {function} callback
@return {object}
Enforces the order of operations for synchronous requests . If a batch s operations cannot be started because required operations have not started yet the batch is deferred until requirements are met .