dis+/node_modules/@google-cloud/pubsub/build/src/publisher/message-queues.js
/**
     * Adds a message to a batch, creating a new batch if need be.
     *
     * @param {object} message The message to publish.
     * @param {PublishCallback} callback The publish callback.
     */
Adds a message to a batch, creating a new batch if need be.
@param {object} message The message to publish.
@param {PublishCallback} callback The publish callback.
Adds a message to a batch creating a new batch if need be . @param { object } message The message to publish . @param { PublishCallback } callback The publish callback .
add(message, callback) {
        if (this.error) {
            callback(this.error);
            return;
        }
        if (this.inFlight) {
            if (this.currentBatch.isAtMax()) {
                this.batches.unshift(this.createBatch());
            }
            this.currentBatch.add(message, callback);
            return;
        }
        if (!this.currentBatch.canFit(message)) {
            this.publish();
        }
        this.currentBatch.add(message, callback);
        if (!this.inFlight) {
            if (this.currentBatch.isFull()) {
                this.publish();
            }
            else if (!this.pending) {
                this.beginNextPublish();
            }
        }
    }
add ( message , callback ) { if ( this . error ) { callback ( this . error ) ; return ; } if ( this . inFlight ) { if ( this . currentBatch . isAtMax ( ) ) { this . batches . unshift ( this . createBatch ( ) ) ; } this . currentBatch . add ( message , callback ) ; return ; } if ( ! this . currentBatch . canFit ( message ) ) { this . publish ( ) ; } this . currentBatch . add ( message , callback ) ; if ( ! this . inFlight ) { if ( this . currentBatch . isFull ( ) ) { this . publish ( ) ; } else if ( ! this . pending ) { this . beginNextPublish ( ) ; } } }
Adds a message to a batch, creating a new batch if need be.
Adds a message to a batch creating a new batch if need be .
// in the event that a batch is currently in flight, we can overfill // the next batch as long as it hasn't hit the API limit // it is possible that we triggered a publish earlier, so we'll need to // check again here