|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.QueuePicker = exports.UnavailablePicker = exports.PickResultType = void 0; |
|
const metadata_1 = require("./metadata"); |
|
const constants_1 = require("./constants"); |
|
var PickResultType; |
|
(function (PickResultType) { |
|
PickResultType[PickResultType["COMPLETE"] = 0] = "COMPLETE"; |
|
PickResultType[PickResultType["QUEUE"] = 1] = "QUEUE"; |
|
PickResultType[PickResultType["TRANSIENT_FAILURE"] = 2] = "TRANSIENT_FAILURE"; |
|
PickResultType[PickResultType["DROP"] = 3] = "DROP"; |
|
})(PickResultType || (exports.PickResultType = PickResultType = {})); |
|
|
|
|
|
|
|
|
|
class UnavailablePicker { |
|
constructor(status) { |
|
this.status = Object.assign({ code: constants_1.Status.UNAVAILABLE, details: 'No connection established', metadata: new metadata_1.Metadata() }, status); |
|
} |
|
pick(pickArgs) { |
|
return { |
|
pickResultType: PickResultType.TRANSIENT_FAILURE, |
|
subchannel: null, |
|
status: this.status, |
|
onCallStarted: null, |
|
onCallEnded: null, |
|
}; |
|
} |
|
} |
|
exports.UnavailablePicker = UnavailablePicker; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QueuePicker { |
|
|
|
constructor(loadBalancer, childPicker) { |
|
this.loadBalancer = loadBalancer; |
|
this.childPicker = childPicker; |
|
this.calledExitIdle = false; |
|
} |
|
pick(pickArgs) { |
|
if (!this.calledExitIdle) { |
|
process.nextTick(() => { |
|
this.loadBalancer.exitIdle(); |
|
}); |
|
this.calledExitIdle = true; |
|
} |
|
if (this.childPicker) { |
|
return this.childPicker.pick(pickArgs); |
|
} |
|
else { |
|
return { |
|
pickResultType: PickResultType.QUEUE, |
|
subchannel: null, |
|
status: null, |
|
onCallStarted: null, |
|
onCallEnded: null, |
|
}; |
|
} |
|
} |
|
} |
|
exports.QueuePicker = QueuePicker; |
|
|