Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function receiveMessages(
pubsub: PubSubApi.Pubsub,
subscription: string,
metrics: GoogleMetrics,
cancel: Promise
): Promise {
// Does higher message batching lead to better throughput? 10 is the max that AWS SQS allows.
const maxMessages = 10;
const source = new AbortController();
const request = pubsub.projects.subscriptions.pull(
{
subscription,
requestBody: { returnImmediately: false, maxMessages }
},
{ signal: source.signal }
);
const response = await Promise.race([request, cancel]);
if (!response) {
source.abort();
return { Messages: [] };
}
metrics.outboundBytes += computeHttpResponseBytes(response.headers);
metrics.pubSubBytes +=
it("should throw exception if passed an already aborted signal", async function() {
const client = new CosmosClient({ endpoint, key: masterKey });
try {
const controller = new AbortController();
const signal = controller.signal;
controller.abort();
await client.getDatabaseAccount({ abortSignal: signal });
assert.fail("Must throw when trying to connect to database");
} catch (err) {
assert.equal(err.name, "AbortError", "client should throw exception");
}
});
it("should abort a query", async function() {
async function callFunctionHttps(
url: string,
call: FunctionCallSerialized,
metrics: GoogleMetrics,
cancel: Promise
): Promise {
const source = new AbortController();
try {
const axiosConfig: GaxiosOptions = {
method: "POST",
url,
headers: { "Content-Type": "application/json" },
body: serializeMessage(call),
signal: source.signal,
responseType: "json"
};
const rawResponse = await Promise.race([
gaxios.request(axiosConfig),
cancel
]);
if (!rawResponse) {
log.info(`cancelling gcp invoke`);