How to use the abort-controller.AbortController function in abort-controller

To help you get started, we’ve selected a few abort-controller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github faastjs / faast.js / src / google / google-queue.ts View on Github external
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 +=
github Azure / azure-sdk-for-js / test / functional / client.spec.ts View on Github external
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() {
github faastjs / faast.js / src / google / google-faast.ts View on Github external
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`);

abort-controller

An implementation of WHATWG AbortController interface.

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular abort-controller functions