/var/www/greso.tech/server/nsm/node_modules/@grpc/grpc-js/build/src
NameSizeModeActions
generated/-0755rm
admin.d.ts4470644editdlrm
admin.js12770644editdlrm
admin.js.map4710644editdlrm
backoff-timeout.d.ts21870644editdlrm
backoff-timeout.js50710644editdlrm
backoff-timeout.js.map29110644editdlrm
call-credentials-filter.d.ts6840644editdlrm
call-credentials-filter.js32740644editdlrm
call-credentials-filter.js.map17240644editdlrm
call-credentials.d.ts24070644editdlrm
call-credentials.js51780644editdlrm
call-credentials.js.map33630644editdlrm
call-interface.d.ts28340644editdlrm
call-interface.js31430644editdlrm
call-interface.js.map18880644editdlrm
call-number.d.ts530644editdlrm
call-number.js8850644editdlrm
call-number.js.map2400644editdlrm
call-stream.d.ts57950644editdlrm
call-stream.js301440644editdlrm
call-stream.js.map185160644editdlrm
call.d.ts36000644editdlrm
call.js50730644editdlrm
call.js.map28850644editdlrm
channel-credentials.d.ts38590644editdlrm
channel-credentials.js73160644editdlrm
channel-credentials.js.map36790644editdlrm
channel-options.d.ts27530644editdlrm
channel-options.js24300644editdlrm
channel-options.js.map13460644editdlrm
channel.d.ts37470644editdlrm
channel.js27290644editdlrm
channel.js.map14230644editdlrm
channelz.d.ts39000644editdlrm
channelz.js229800644editdlrm
channelz.js.map173670644editdlrm
client-interceptors.d.ts46110644editdlrm
client-interceptors.js177870644editdlrm
client-interceptors.js.map106010644editdlrm
client.d.ts58170644editdlrm
client.js189740644editdlrm
client.js.map118550644editdlrm
compression-algorithms.d.ts940644editdlrm
compression-algorithms.js11580644editdlrm
compression-algorithms.js.map3110644editdlrm
compression-filter.d.ts12150644editdlrm
compression-filter.js103070644editdlrm
compression-filter.js.map62650644editdlrm
connectivity-state.d.ts1350644editdlrm
connectivity-state.js12640644editdlrm
connectivity-state.js.map3270644editdlrm
constants.d.ts9440644editdlrm
constants.js31060644editdlrm
constants.js.map9500644editdlrm
control-plane-status.d.ts1690644editdlrm
control-plane-status.js15810644editdlrm
control-plane-status.js.map6700644editdlrm
deadline-filter.d.ts8250644editdlrm
deadline-filter.js36280644editdlrm
deadline-filter.js.map25790644editdlrm
deadline.d.ts7520644editdlrm
deadline.js33510644editdlrm
deadline.js.map19190644editdlrm
duration.d.ts2670644editdlrm
duration.js12530644editdlrm
duration.js.map6060644editdlrm
error.d.ts1340644editdlrm
error.js12360644editdlrm
error.js.map5200644editdlrm
events.d.ts5210644editdlrm
events.js7110644editdlrm
events.js.map1310644editdlrm
experimental.d.ts13140644editdlrm
experimental.js42110644editdlrm
experimental.js.map7640644editdlrm
filter-stack.d.ts9690644editdlrm
filter-stack.js25420644editdlrm
filter-stack.js.map20900644editdlrm
filter.d.ts11920644editdlrm
filter.js11110644editdlrm
filter.js.map4640644editdlrm
http_proxy.d.ts7270644editdlrm
http_proxy.js94240644editdlrm
http_proxy.js.map60840644editdlrm
index.d.ts53500644editdlrm
index.js92340644editdlrm
index.js.map30990644editdlrm
internal-channel.d.ts48890644editdlrm
internal-channel.js214740644editdlrm
internal-channel.js.map142310644editdlrm
load-balancer-child-handler.d.ts8150644editdlrm
load-balancer-child-handler.js52360644editdlrm
load-balancer-child-handler.js.map32460644editdlrm
load-balancer-outlier-detection.d.ts26630644editdlrm
load-balancer-outlier-detection.js257850644editdlrm
load-balancer-outlier-detection.js.map183100644editdlrm
load-balancer-pick-first.d.ts28280644editdlrm
load-balancer-pick-first.js175090644editdlrm
load-balancer-pick-first.js.map95060644editdlrm
load-balancer-round-robin.d.ts8040644editdlrm
load-balancer-round-robin.js78160644editdlrm
load-balancer-round-robin.js.map50190644editdlrm
load-balancer.d.ts44530644editdlrm
load-balancer.js48450644editdlrm
load-balancer.js.map24280644editdlrm
load-balancing-call.d.ts18470644editdlrm
load-balancing-call.js116470644editdlrm
load-balancing-call.js.map75310644editdlrm
logging.d.ts4770644editdlrm
logging.js40060644editdlrm
logging.js.map27950644editdlrm
make-client.d.ts30020644editdlrm
make-client.js54980644editdlrm
make-client.js.map31120644editdlrm
max-message-size-filter.d.ts7620644editdlrm
max-message-size-filter.js33600644editdlrm
max-message-size-filter.js.map15960644editdlrm
metadata.d.ts32410644editdlrm
metadata.js88390644editdlrm
metadata.js.map56450644editdlrm
object-stream.d.ts16040644editdlrm
object-stream.js7180644editdlrm
object-stream.js.map1450644editdlrm
picker.d.ts30390644editdlrm
picker.js31080644editdlrm
picker.js.map12520644editdlrm
resolver-dns.d.ts2320644editdlrm
resolver-dns.js133900644editdlrm
resolver-dns.js.map75580644editdlrm
resolver-ip.d.ts390644editdlrm
resolver-ip.js38330644editdlrm
resolver-ip.js.map25120644editdlrm
resolver-uds.d.ts390644editdlrm
resolver-uds.js15220644editdlrm
resolver-uds.js.map8230644editdlrm
resolver.d.ts42880644editdlrm
resolver.js32310644editdlrm
resolver.js.map13990644editdlrm
resolving-call.d.ts17540644editdlrm
resolving-call.js107110644editdlrm
resolving-call.js.map85510644editdlrm
resolving-load-balancer.d.ts28390644editdlrm
resolving-load-balancer.js120270644editdlrm
resolving-load-balancer.js.map62850644editdlrm
retrying-call.d.ts35280644editdlrm
retrying-call.js246580644editdlrm
retrying-call.js.map183180644editdlrm
server-call.d.ts82830644editdlrm
server-call.js242810644editdlrm
server-call.js.map195340644editdlrm
server-credentials.d.ts5110644editdlrm
server-credentials.js28340644editdlrm
server-credentials.js.map17870644editdlrm
server.d.ts22140644editdlrm
server.js382510644editdlrm
server.js.map268510644editdlrm
service-config.d.ts21630644editdlrm
service-config.js161610644editdlrm
service-config.js.map104750644editdlrm
status-builder.d.ts6570644editdlrm
status-builder.js17670644editdlrm
status-builder.js.map9720644editdlrm
stream-decoder.d.ts3130644editdlrm
stream-decoder.js42670644editdlrm
stream-decoder.js.map27150644editdlrm
subchannel-address.d.ts9500644editdlrm
subchannel-address.js22280644editdlrm
subchannel-address.js.map11950644editdlrm
subchannel-call.d.ts22580644editdlrm
subchannel-call.js200120644editdlrm
subchannel-call.js.map111560644editdlrm
subchannel-interface.d.ts18420644editdlrm
subchannel-interface.js17030644editdlrm
subchannel-interface.js.map9740644editdlrm
subchannel-pool.d.ts14720644editdlrm
subchannel-pool.js56740644editdlrm
subchannel-pool.js.map24940644editdlrm
subchannel.d.ts46540644editdlrm
subchannel.js145900644editdlrm
subchannel.js.map81870644editdlrm
tls-helpers.d.ts1490644editdlrm
tls-helpers.js12720644editdlrm
tls-helpers.js.map5020644editdlrm
transport.d.ts44730644editdlrm
transport.js268880644editdlrm
transport.js.map148010644editdlrm
uri-parser.d.ts3570644editdlrm
uri-parser.js32740644editdlrm
uri-parser.js.map20100644editdlrm
Edit: /var/www/greso.tech/server/nsm/node_modules/@grpc/grpc-js/build/src/retrying-call.js (24658B)
"use strict"; /* * Copyright 2022 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryingCall = exports.MessageBufferTracker = exports.RetryThrottler = void 0; const constants_1 = require("./constants"); const metadata_1 = require("./metadata"); const logging = require("./logging"); const TRACER_NAME = 'retrying_call'; class RetryThrottler { constructor(maxTokens, tokenRatio, previousRetryThrottler) { this.maxTokens = maxTokens; this.tokenRatio = tokenRatio; if (previousRetryThrottler) { /* When carrying over tokens from a previous config, rescale them to the * new max value */ this.tokens = previousRetryThrottler.tokens * (maxTokens / previousRetryThrottler.maxTokens); } else { this.tokens = maxTokens; } } addCallSucceeded() { this.tokens = Math.max(this.tokens + this.tokenRatio, this.maxTokens); } addCallFailed() { this.tokens = Math.min(this.tokens - 1, 0); } canRetryCall() { return this.tokens > this.maxTokens / 2; } } exports.RetryThrottler = RetryThrottler; class MessageBufferTracker { constructor(totalLimit, limitPerCall) { this.totalLimit = totalLimit; this.limitPerCall = limitPerCall; this.totalAllocated = 0; this.allocatedPerCall = new Map(); } allocate(size, callId) { var _a; const currentPerCall = (_a = this.allocatedPerCall.get(callId)) !== null && _a !== void 0 ? _a : 0; if (this.limitPerCall - currentPerCall < size || this.totalLimit - this.totalAllocated < size) { return false; } this.allocatedPerCall.set(callId, currentPerCall + size); this.totalAllocated += size; return true; } free(size, callId) { var _a; if (this.totalAllocated < size) { throw new Error(`Invalid buffer allocation state: call ${callId} freed ${size} > total allocated ${this.totalAllocated}`); } this.totalAllocated -= size; const currentPerCall = (_a = this.allocatedPerCall.get(callId)) !== null && _a !== void 0 ? _a : 0; if (currentPerCall < size) { throw new Error(`Invalid buffer allocation state: call ${callId} freed ${size} > allocated for call ${currentPerCall}`); } this.allocatedPerCall.set(callId, currentPerCall - size); } freeAll(callId) { var _a; const currentPerCall = (_a = this.allocatedPerCall.get(callId)) !== null && _a !== void 0 ? _a : 0; if (this.totalAllocated < currentPerCall) { throw new Error(`Invalid buffer allocation state: call ${callId} allocated ${currentPerCall} > total allocated ${this.totalAllocated}`); } this.totalAllocated -= currentPerCall; this.allocatedPerCall.delete(callId); } } exports.MessageBufferTracker = MessageBufferTracker; const PREVIONS_RPC_ATTEMPTS_METADATA_KEY = 'grpc-previous-rpc-attempts'; class RetryingCall { constructor(channel, callConfig, methodName, host, credentials, deadline, callNumber, bufferTracker, retryThrottler) { this.channel = channel; this.callConfig = callConfig; this.methodName = methodName; this.host = host; this.credentials = credentials; this.deadline = deadline; this.callNumber = callNumber; this.bufferTracker = bufferTracker; this.retryThrottler = retryThrottler; this.listener = null; this.initialMetadata = null; this.underlyingCalls = []; this.writeBuffer = []; /** * The offset of message indices in the writeBuffer. For example, if * writeBufferOffset is 10, message 10 is in writeBuffer[0] and message 15 * is in writeBuffer[5]. */ this.writeBufferOffset = 0; /** * Tracks whether a read has been started, so that we know whether to start * reads on new child calls. This only matters for the first read, because * once a message comes in the child call becomes committed and there will * be no new child calls. */ this.readStarted = false; this.transparentRetryUsed = false; /** * Number of attempts so far */ this.attempts = 0; this.hedgingTimer = null; this.committedCallIndex = null; this.initialRetryBackoffSec = 0; this.nextRetryBackoffSec = 0; if (callConfig.methodConfig.retryPolicy) { this.state = 'RETRY'; const retryPolicy = callConfig.methodConfig.retryPolicy; this.nextRetryBackoffSec = this.initialRetryBackoffSec = Number(retryPolicy.initialBackoff.substring(0, retryPolicy.initialBackoff.length - 1)); } else if (callConfig.methodConfig.hedgingPolicy) { this.state = 'HEDGING'; } else { this.state = 'TRANSPARENT_ONLY'; } } getCallNumber() { return this.callNumber; } trace(text) { logging.trace(constants_1.LogVerbosity.DEBUG, TRACER_NAME, '[' + this.callNumber + '] ' + text); } reportStatus(statusObject) { this.trace('ended with status: code=' + statusObject.code + ' details="' + statusObject.details + '"'); this.bufferTracker.freeAll(this.callNumber); this.writeBufferOffset = this.writeBufferOffset + this.writeBuffer.length; this.writeBuffer = []; process.nextTick(() => { var _a; // Explicitly construct status object to remove progress field (_a = this.listener) === null || _a === void 0 ? void 0 : _a.onReceiveStatus({ code: statusObject.code, details: statusObject.details, metadata: statusObject.metadata }); }); } cancelWithStatus(status, details) { this.trace('cancelWithStatus code: ' + status + ' details: "' + details + '"'); this.reportStatus({ code: status, details, metadata: new metadata_1.Metadata() }); for (const { call } of this.underlyingCalls) { call.cancelWithStatus(status, details); } } getPeer() { if (this.committedCallIndex !== null) { return this.underlyingCalls[this.committedCallIndex].call.getPeer(); } else { return 'unknown'; } } getBufferEntry(messageIndex) { var _a; return (_a = this.writeBuffer[messageIndex - this.writeBufferOffset]) !== null && _a !== void 0 ? _a : { entryType: 'FREED', allocated: false }; } getNextBufferIndex() { return this.writeBufferOffset + this.writeBuffer.length; } clearSentMessages() { if (this.state !== 'COMMITTED') { return; } const earliestNeededMessageIndex = this.underlyingCalls[this.committedCallIndex].nextMessageToSend; for (let messageIndex = this.writeBufferOffset; messageIndex < earliestNeededMessageIndex; messageIndex++) { const bufferEntry = this.getBufferEntry(messageIndex); if (bufferEntry.allocated) { this.bufferTracker.free(bufferEntry.message.message.length, this.callNumber); } } this.writeBuffer = this.writeBuffer.slice(earliestNeededMessageIndex - this.writeBufferOffset); this.writeBufferOffset = earliestNeededMessageIndex; } commitCall(index) { if (this.state === 'COMMITTED') { return; } if (this.underlyingCalls[index].state === 'COMPLETED') { return; } this.trace('Committing call [' + this.underlyingCalls[index].call.getCallNumber() + '] at index ' + index); this.state = 'COMMITTED'; this.committedCallIndex = index; for (let i = 0; i < this.underlyingCalls.length; i++) { if (i === index) { continue; } if (this.underlyingCalls[i].state === 'COMPLETED') { continue; } this.underlyingCalls[i].state = 'COMPLETED'; this.underlyingCalls[i].call.cancelWithStatus(constants_1.Status.CANCELLED, 'Discarded in favor of other hedged attempt'); } this.clearSentMessages(); } commitCallWithMostMessages() { if (this.state === 'COMMITTED') { return; } let mostMessages = -1; let callWithMostMessages = -1; for (const [index, childCall] of this.underlyingCalls.entries()) { if (childCall.state === 'ACTIVE' && childCall.nextMessageToSend > mostMessages) { mostMessages = childCall.nextMessageToSend; callWithMostMessages = index; } } if (callWithMostMessages === -1) { /* There are no active calls, disable retries to force the next call that * is started to be committed. */ this.state = 'TRANSPARENT_ONLY'; } else { this.commitCall(callWithMostMessages); } } isStatusCodeInList(list, code) { return list.some((value => value === code || value.toString().toLowerCase() === constants_1.Status[code].toLowerCase())); } getNextRetryBackoffMs() { var _a; const retryPolicy = (_a = this.callConfig) === null || _a === void 0 ? void 0 : _a.methodConfig.retryPolicy; if (!retryPolicy) { return 0; } const nextBackoffMs = Math.random() * this.nextRetryBackoffSec * 1000; const maxBackoffSec = Number(retryPolicy.maxBackoff.substring(0, retryPolicy.maxBackoff.length - 1)); this.nextRetryBackoffSec = Math.min(this.nextRetryBackoffSec * retryPolicy.backoffMultiplier, maxBackoffSec); return nextBackoffMs; } maybeRetryCall(pushback, callback) { if (this.state !== 'RETRY') { callback(false); return; } const retryPolicy = this.callConfig.methodConfig.retryPolicy; if (this.attempts >= Math.min(retryPolicy.maxAttempts, 5)) { callback(false); return; } let retryDelayMs; if (pushback === null) { retryDelayMs = this.getNextRetryBackoffMs(); } else if (pushback < 0) { this.state = 'TRANSPARENT_ONLY'; callback(false); return; } else { retryDelayMs = pushback; this.nextRetryBackoffSec = this.initialRetryBackoffSec; } setTimeout(() => { var _a, _b; if (this.state !== 'RETRY') { callback(false); return; } if ((_b = (_a = this.retryThrottler) === null || _a === void 0 ? void 0 : _a.canRetryCall()) !== null && _b !== void 0 ? _b : true) { callback(true); this.attempts += 1; this.startNewAttempt(); } }, retryDelayMs); } countActiveCalls() { let count = 0; for (const call of this.underlyingCalls) { if ((call === null || call === void 0 ? void 0 : call.state) === 'ACTIVE') { count += 1; } } return count; } handleProcessedStatus(status, callIndex, pushback) { var _a, _b, _c; switch (this.state) { case 'COMMITTED': case 'TRANSPARENT_ONLY': this.commitCall(callIndex); this.reportStatus(status); break; case 'HEDGING': if (this.isStatusCodeInList((_a = this.callConfig.methodConfig.hedgingPolicy.nonFatalStatusCodes) !== null && _a !== void 0 ? _a : [], status.code)) { (_b = this.retryThrottler) === null || _b === void 0 ? void 0 : _b.addCallFailed(); let delayMs; if (pushback === null) { delayMs = 0; } else if (pushback < 0) { this.state = 'TRANSPARENT_ONLY'; this.commitCall(callIndex); this.reportStatus(status); return; } else { delayMs = pushback; } setTimeout(() => { this.maybeStartHedgingAttempt(); // If after trying to start a call there are no active calls, this was the last one if (this.countActiveCalls() === 0) { this.commitCall(callIndex); this.reportStatus(status); } }, delayMs); } else { this.commitCall(callIndex); this.reportStatus(status); } break; case 'RETRY': if (this.isStatusCodeInList(this.callConfig.methodConfig.retryPolicy.retryableStatusCodes, status.code)) { (_c = this.retryThrottler) === null || _c === void 0 ? void 0 : _c.addCallFailed(); this.maybeRetryCall(pushback, (retried) => { if (!retried) { this.commitCall(callIndex); this.reportStatus(status); } }); } else { this.commitCall(callIndex); this.reportStatus(status); } break; } } getPushback(metadata) { const mdValue = metadata.get('grpc-retry-pushback-ms'); if (mdValue.length === 0) { return null; } try { return parseInt(mdValue[0]); } catch (e) { return -1; } } handleChildStatus(status, callIndex) { var _a; if (this.underlyingCalls[callIndex].state === 'COMPLETED') { return; } this.trace('state=' + this.state + ' handling status with progress ' + status.progress + ' from child [' + this.underlyingCalls[callIndex].call.getCallNumber() + '] in state ' + this.underlyingCalls[callIndex].state); this.underlyingCalls[callIndex].state = 'COMPLETED'; if (status.code === constants_1.Status.OK) { (_a = this.retryThrottler) === null || _a === void 0 ? void 0 : _a.addCallSucceeded(); this.commitCall(callIndex); this.reportStatus(status); return; } if (this.state === 'COMMITTED') { this.reportStatus(status); return; } const pushback = this.getPushback(status.metadata); switch (status.progress) { case 'NOT_STARTED': // RPC never leaves the client, always safe to retry this.startNewAttempt(); break; case 'REFUSED': // RPC reaches the server library, but not the server application logic if (this.transparentRetryUsed) { this.handleProcessedStatus(status, callIndex, pushback); } else { this.transparentRetryUsed = true; this.startNewAttempt(); } ; break; case 'DROP': this.commitCall(callIndex); this.reportStatus(status); break; case 'PROCESSED': this.handleProcessedStatus(status, callIndex, pushback); break; } } maybeStartHedgingAttempt() { if (this.state !== 'HEDGING') { return; } if (!this.callConfig.methodConfig.hedgingPolicy) { return; } const hedgingPolicy = this.callConfig.methodConfig.hedgingPolicy; if (this.attempts >= Math.min(hedgingPolicy.maxAttempts, 5)) { return; } this.attempts += 1; this.startNewAttempt(); this.maybeStartHedgingTimer(); } maybeStartHedgingTimer() { var _a, _b, _c; if (this.hedgingTimer) { clearTimeout(this.hedgingTimer); } if (this.state !== 'HEDGING') { return; } if (!this.callConfig.methodConfig.hedgingPolicy) { return; } const hedgingPolicy = this.callConfig.methodConfig.hedgingPolicy; if (this.attempts >= Math.min(hedgingPolicy.maxAttempts, 5)) { return; } const hedgingDelayString = (_a = hedgingPolicy.hedgingDelay) !== null && _a !== void 0 ? _a : '0s'; const hedgingDelaySec = Number(hedgingDelayString.substring(0, hedgingDelayString.length - 1)); this.hedgingTimer = setTimeout(() => { this.maybeStartHedgingAttempt(); }, hedgingDelaySec * 1000); (_c = (_b = this.hedgingTimer).unref) === null || _c === void 0 ? void 0 : _c.call(_b); } startNewAttempt() { const child = this.channel.createLoadBalancingCall(this.callConfig, this.methodName, this.host, this.credentials, this.deadline); this.trace('Created child call [' + child.getCallNumber() + '] for attempt ' + this.attempts); const index = this.underlyingCalls.length; this.underlyingCalls.push({ state: 'ACTIVE', call: child, nextMessageToSend: 0 }); const previousAttempts = this.attempts - 1; const initialMetadata = this.initialMetadata.clone(); if (previousAttempts > 0) { initialMetadata.set(PREVIONS_RPC_ATTEMPTS_METADATA_KEY, `${previousAttempts}`); } let receivedMetadata = false; child.start(initialMetadata, { onReceiveMetadata: metadata => { this.trace('Received metadata from child [' + child.getCallNumber() + ']'); this.commitCall(index); receivedMetadata = true; if (previousAttempts > 0) { metadata.set(PREVIONS_RPC_ATTEMPTS_METADATA_KEY, `${previousAttempts}`); } if (this.underlyingCalls[index].state === 'ACTIVE') { this.listener.onReceiveMetadata(metadata); } }, onReceiveMessage: message => { this.trace('Received message from child [' + child.getCallNumber() + ']'); this.commitCall(index); if (this.underlyingCalls[index].state === 'ACTIVE') { this.listener.onReceiveMessage(message); } }, onReceiveStatus: status => { this.trace('Received status from child [' + child.getCallNumber() + ']'); if (!receivedMetadata && previousAttempts > 0) { status.metadata.set(PREVIONS_RPC_ATTEMPTS_METADATA_KEY, `${previousAttempts}`); } this.handleChildStatus(status, index); } }); this.sendNextChildMessage(index); if (this.readStarted) { child.startRead(); } } start(metadata, listener) { this.trace('start called'); this.listener = listener; this.initialMetadata = metadata; this.attempts += 1; this.startNewAttempt(); this.maybeStartHedgingTimer(); } handleChildWriteCompleted(childIndex) { var _a, _b; const childCall = this.underlyingCalls[childIndex]; const messageIndex = childCall.nextMessageToSend; (_b = (_a = this.getBufferEntry(messageIndex)).callback) === null || _b === void 0 ? void 0 : _b.call(_a); this.clearSentMessages(); childCall.nextMessageToSend += 1; this.sendNextChildMessage(childIndex); } sendNextChildMessage(childIndex) { const childCall = this.underlyingCalls[childIndex]; if (childCall.state === 'COMPLETED') { return; } if (this.getBufferEntry(childCall.nextMessageToSend)) { const bufferEntry = this.getBufferEntry(childCall.nextMessageToSend); switch (bufferEntry.entryType) { case 'MESSAGE': childCall.call.sendMessageWithContext({ callback: (error) => { // Ignore error this.handleChildWriteCompleted(childIndex); } }, bufferEntry.message.message); break; case 'HALF_CLOSE': childCall.nextMessageToSend += 1; childCall.call.halfClose(); break; case 'FREED': // Should not be possible break; } } } sendMessageWithContext(context, message) { var _a; this.trace('write() called with message of length ' + message.length); const writeObj = { message, flags: context.flags, }; const messageIndex = this.getNextBufferIndex(); const bufferEntry = { entryType: 'MESSAGE', message: writeObj, allocated: this.bufferTracker.allocate(message.length, this.callNumber) }; this.writeBuffer.push(bufferEntry); if (bufferEntry.allocated) { (_a = context.callback) === null || _a === void 0 ? void 0 : _a.call(context); for (const [callIndex, call] of this.underlyingCalls.entries()) { if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) { call.call.sendMessageWithContext({ callback: (error) => { // Ignore error this.handleChildWriteCompleted(callIndex); } }, message); } } } else { this.commitCallWithMostMessages(); // commitCallWithMostMessages can fail if we are between ping attempts if (this.committedCallIndex === null) { return; } const call = this.underlyingCalls[this.committedCallIndex]; bufferEntry.callback = context.callback; if (call.state === 'ACTIVE' && call.nextMessageToSend === messageIndex) { call.call.sendMessageWithContext({ callback: (error) => { // Ignore error this.handleChildWriteCompleted(this.committedCallIndex); } }, message); } } } startRead() { this.trace('startRead called'); this.readStarted = true; for (const underlyingCall of this.underlyingCalls) { if ((underlyingCall === null || underlyingCall === void 0 ? void 0 : underlyingCall.state) === 'ACTIVE') { underlyingCall.call.startRead(); } } } halfClose() { this.trace('halfClose called'); const halfCloseIndex = this.getNextBufferIndex(); this.writeBuffer.push({ entryType: 'HALF_CLOSE', allocated: false }); for (const call of this.underlyingCalls) { if ((call === null || call === void 0 ? void 0 : call.state) === 'ACTIVE' && call.nextMessageToSend === halfCloseIndex) { call.nextMessageToSend += 1; call.call.halfClose(); } } } setCredentials(newCredentials) { throw new Error("Method not implemented."); } getMethod() { return this.methodName; } getHost() { return this.host; } } exports.RetryingCall = RetryingCall; //# sourceMappingURL=retrying-call.js.map