Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@azure/core-util

Package Overview
Dependencies
Maintainers
1
Versions
214
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/core-util - npm Package Compare versions

Comparing version 1.1.2-alpha.20230215.3 to 1.2.0-alpha.20230228.2

dist-esm/src/createAbortablePromise.js

41

dist-esm/src/delay.js
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { AbortError } from "@azure/abort-controller";
import { createAbortablePromise } from "./createAbortablePromise";
const StandardAbortMessage = "The delay was aborted.";
/**
* Creates an abortable promise.
* @param buildPromise - A function that takes the resolve and reject functions as parameters.
* @param options - The options for the abortable promise.
* @returns A promise that can be aborted.
* @internal
*/
export function createAbortablePromise(buildPromise, options) {
const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
return new Promise((resolve, reject) => {
function rejectOnAbort() {
reject(new AbortError(abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : "The operation was aborted."));
}
function removeListeners() {
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
}
function onAbort() {
cleanupBeforeAbort === null || cleanupBeforeAbort === void 0 ? void 0 : cleanupBeforeAbort();
removeListeners();
rejectOnAbort();
}
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
return rejectOnAbort();
}
try {
buildPromise((x) => {
removeListeners();
resolve(x);
}, (x) => {
removeListeners();
reject(x);
});
}
catch (err) {
reject(err);
}
abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort);
});
}
/**
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.

@@ -46,0 +7,0 @@ * @param timeInMs - The number of milliseconds to be delayed.

@@ -5,2 +5,3 @@ // Copyright (c) Microsoft Corporation.

export { delay } from "./delay";
export { createAbortablePromise } from "./createAbortablePromise";
export { getRandomIntegerInclusive } from "./random";

@@ -7,0 +8,0 @@ export { isObject } from "./object";

@@ -17,3 +17,2 @@ 'use strict';

// Copyright (c) Microsoft Corporation.
const StandardAbortMessage = "The delay was aborted.";
/**

@@ -24,3 +23,2 @@ * Creates an abortable promise.

* @returns A promise that can be aborted.
* @internal
*/

@@ -59,2 +57,5 @@ function createAbortablePromise(buildPromise, options) {

}
// Copyright (c) Microsoft Corporation.
const StandardAbortMessage = "The delay was aborted.";
/**

@@ -209,2 +210,3 @@ * A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.

exports.computeSha256Hmac = computeSha256Hmac;
exports.createAbortablePromise = createAbortablePromise;
exports.delay = delay;

@@ -211,0 +213,0 @@ exports.getErrorMessage = getErrorMessage;

{
"name": "@azure/core-util",
"version": "1.1.2-alpha.20230215.3",
"version": "1.2.0-alpha.20230228.2",
"description": "Core library for shared utility methods",

@@ -5,0 +5,0 @@ "sdk-type": "client",

@@ -16,2 +16,20 @@ import { AbortSignalLike } from '@azure/abort-controller';

/**
* Creates an abortable promise.
* @param buildPromise - A function that takes the resolve and reject functions as parameters.
* @param options - The options for the abortable promise.
* @returns A promise that can be aborted.
*/
export declare function createAbortablePromise<T>(buildPromise: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, options?: CreateAbortablePromiseOptions): Promise<T>;
/**
* Options for the createAbortablePromise function.
*/
export declare interface CreateAbortablePromiseOptions {
/** A function to be called if the promise was aborted */
cleanupBeforeAbort?: () => void;
/** An abort signal */
abortSignal?: AbortSignalLike;
/** An abort error message */
abortErrorMsg?: string;
}
/**
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.

@@ -18,0 +36,0 @@ * @param timeInMs - The number of milliseconds to be delayed.

@@ -19,2 +19,22 @@ import { AbortSignalLike } from '@azure/abort-controller';

/**
* Creates an abortable promise.
* @param buildPromise - A function that takes the resolve and reject functions as parameters.
* @param options - The options for the abortable promise.
* @returns A promise that can be aborted.
*/
export declare function createAbortablePromise<T>(buildPromise: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, options?: CreateAbortablePromiseOptions): Promise<T>;
/**
* Options for the createAbortablePromise function.
*/
export declare interface CreateAbortablePromiseOptions {
/** A function to be called if the promise was aborted */
cleanupBeforeAbort?: () => void;
/** An abort signal */
abortSignal?: AbortSignalLike;
/** An abort error message */
abortErrorMsg?: string;
}
/**
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.

@@ -21,0 +41,0 @@ * @param timeInMs - The number of milliseconds to be delayed.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc