Tanya  Shields

Tanya Shields

1595388300

How to cancel operations in the Azure SDK for JavaScript/TypeScript

Cancelling in-progress network operations is critical for applications to maintain responsiveness and avoid doing work that isn’t needed anymore. There are many situations where you want to cancel on-going work, for example when you are:

  • downloading a large file from Azure Storage and the user wants to cancel the download
  • processing events from an Event Hub and you need to gracefully shut down in order to scale down or to apply updates
  • running an operation that might take a while and you don’t want to wait longer than a fixed amount of time
  • running multiple operations in parallel and getting one result makes the other results irrelevant

The new Azure SDK libraries for JavaScript and TypeScript have adopted abort signals situations like these.

AbortController & AbortSignal

AbortController and AbortSignal are standard features in the browser and are used with the fetch API to abort in-progress network requests. The controller is responsible for triggering the cancellation, and signals are responsible for notifying when a cancellation has been triggered. This separation of concerns enables you to safely pass the abort signal to other parts of your application without worrying about it unintentionally cancelling the request.

If you’re only targeting fairly modern browsers, you can use the built-in AbortController and AbortSignal and everything will work fine. If you’re targeting Node.js, or if you want to take advantage of linked signals or other features that I’ll cover later in this post, you can use the implementation in the Azure SDK found in the @azure/abort-controller npm package.

To abort an in-progress request such as an upload or download in storage, create a new AbortController and pass its signal into the method you might want to cancel later:

// Omit this line if you want to use the AbortSignal built into the browser.
import { AbortController } from "@azure/abort-controller";

// create a controller and get its signal
const controller = new AbortController();
const abortSignal = controller.signal;

// pass the abortSignal into the API you want to cancel
await blobClient.download({ abortSignal })

// then sometime later, cancel it!
controller.abort();

Note that cancelling using AbortController only affects client-side code. It does not notify the service that cancellation has happened. For example, if you are uploading a key into Key Vault and you cancel before it finishes, the key might still be created.

#azure sdk #javascript #programming #typescript

What is GEEK

Buddha Community

How to cancel operations in the Azure SDK for JavaScript/TypeScript
Aisu  Joesph

Aisu Joesph

1624342320

Azure SDK Release (June 2021)

Release Highlights

Welcome to the June release of the Azure SDK. We have updated the following libraries:

Stable Releases

  • Azure Cognitive Search for .NET, Java (version 11.4), and JavaScript and Python (version 11.2)
  • Adds stable features and bug fixes from the beta releases. See the Cognitive Search changelog for more details.
  • Preview service features not generally available yet, like Semantic Search and Normalizers, are not included in this release.
  • Support for geospatial types in core for .NET and Java.
  • Support for knowledge store.
  • Azure Data Tables version 12.0
  • Read more here: Announcing the new Azure Data Table Libraries.
  • Azure SDK for Python (Conda) packages are now generally available in the Microsoft channel.
  • Read more here: Introducing the Azure SDK for Python (Conda).
  • See also: https://anaconda.org/microsoft.
  • Event Grid for Java (version 4.4), JavaScript and Python (version 4.3)
  • Adds new system events definition for Storage Blob and Azure Communication Service.
  • Form Recognizer version 3.1
  • This release marks the stability of the changes introduced in package versions 3.1.0-beta.1 through 3.1.0-beta.3.
  • Core, Identity, and Azure Storage for C++ version 1.0
  • This release marks the general availability for Core, Identity, and Azure Storage.
  • To get started and view samples, view the README on the Azure SDK for C++ repo.
  • Quickstarts and documentation are being updated at Microsoft Docs.
  • Key Vault Administration, Certificates, Keys and Secrets.
  • Key Vault Administration is a new library that allows for role-based access control (RBAC), and backup and restore operations for Managed HSM.
  • Key Vault Keys added functionality:
  • Support for Managed HSM.
  • Cryptography clients now support executing all operations locally if given a JsonWebKey.
  • Support for creating and importing symmetric keys for Managed HSM.
  • RSA keys now support providing a public exponent.

#azure sdk #azure #azure-sdk #javascript #python #release #sdk

Tanya  Shields

Tanya Shields

1595388300

How to cancel operations in the Azure SDK for JavaScript/TypeScript

Cancelling in-progress network operations is critical for applications to maintain responsiveness and avoid doing work that isn’t needed anymore. There are many situations where you want to cancel on-going work, for example when you are:

  • downloading a large file from Azure Storage and the user wants to cancel the download
  • processing events from an Event Hub and you need to gracefully shut down in order to scale down or to apply updates
  • running an operation that might take a while and you don’t want to wait longer than a fixed amount of time
  • running multiple operations in parallel and getting one result makes the other results irrelevant

The new Azure SDK libraries for JavaScript and TypeScript have adopted abort signals situations like these.

AbortController & AbortSignal

AbortController and AbortSignal are standard features in the browser and are used with the fetch API to abort in-progress network requests. The controller is responsible for triggering the cancellation, and signals are responsible for notifying when a cancellation has been triggered. This separation of concerns enables you to safely pass the abort signal to other parts of your application without worrying about it unintentionally cancelling the request.

If you’re only targeting fairly modern browsers, you can use the built-in AbortController and AbortSignal and everything will work fine. If you’re targeting Node.js, or if you want to take advantage of linked signals or other features that I’ll cover later in this post, you can use the implementation in the Azure SDK found in the @azure/abort-controller npm package.

To abort an in-progress request such as an upload or download in storage, create a new AbortController and pass its signal into the method you might want to cancel later:

// Omit this line if you want to use the AbortSignal built into the browser.
import { AbortController } from "@azure/abort-controller";

// create a controller and get its signal
const controller = new AbortController();
const abortSignal = controller.signal;

// pass the abortSignal into the API you want to cancel
await blobClient.download({ abortSignal })

// then sometime later, cancel it!
controller.abort();

Note that cancelling using AbortController only affects client-side code. It does not notify the service that cancellation has happened. For example, if you are uploading a key into Key Vault and you cancel before it finishes, the key might still be created.

#azure sdk #javascript #programming #typescript

Santosh J

1622036598

JavaScript compound assignment operators

JavaScript is unarguablly one of the most common things you’ll learn when you start programming for the web. Here’s a small post on JavaScript compound assignment operators and how we use them.

The compound assignment operators consist of a binary operator and the simple assignment operator.

The binary operators, work with two operands. For example a+b where + is the operator and the a, b are operands. Simple assignment operator is used to assign values to a variable(s).

It’s quite common to modify values stored in variables. To make this process a little quicker, we use compound assignment operators.

They are:

  • +=
  • -+
  • *=
  • /=

You can also check my video tutorial compound assignment operators.

Let’s consider an example. Suppose price = 5 and we want to add ten more to it.

var price = 5;
price = price + 10;

We added ten to price. Look at the repetitive price variable. We could easily use a compound += to reduce this. We do this instead.

price += 5;

Awesome. Isn’t it? What’s the value of price now? Practice and comment below. If you don’t know how to practice check these lessons.

Lets bring down the price by 5 again and display it.
We use console.log command to display what is stored in the variable. It is very help for debugging.
Debugging let’s you find errors or bugs in your code. More on this later.

price -= 5;
console.log(price);

Lets multiply price and show it.

price *=5;
console.log(price);

and finally we will divide it.

price /=5;
console.log(price);

If you have any doubts, comment below.

#javascript #javascript compound assignment operators #javascript binary operators #javascript simple assignment operator #doers javascript

Async Iterators in the Azure SDK for JavaScript/TypeScript

A common feature in cloud APIs is paging for list results. Result sets may be massive – you could have thousands of blobs in a container, for example. Getting all results at once can cause delays in transmission and excessive load on the backend, and might even be so big it won’t fit into memory in your client. So services offer potentially large collections in pages and developers request one page of results at a time.

The Azure SDK for Javascript and TypeScript abstracts away the details of requesting pages from the service. You write a normal loop, and we take care of the rest. For example, here is the code that iterates through a list of containers in Storage:

const containers = blobServiceClient.listContainers();
for await (const container of containers) {
  console.log(`Container: ${container.name}`);
}

How is this done? We use features that were added to recent editions of JavaScript; most notably async iterators. Async Iterators represent a stream of data that is loaded asynchronously. They are used across the Azure SDK to represent asynchronous streams of data such as paginated APIs like above.

Async Iterators, the Async Generators that produce them, and the for - await - of  loops loops that consume them were added in the ES2018 edition of the JavaScript standard. They are supported natively in recent version of modern browsers, but TypeScript can compile them down to previous versions of JavaScript.

If you’re already familiar with async functions, promises, generators, and iterators, feel free to skip the background below. If not, that’s great, most of this blog is for you!

#azure sdk #javascript #typescript #programming

Brain  Crist

Brain Crist

1597820400

Azure SDK Release (August 2020)

Thank you for your interest in the new Azure SDKs! We release new features, improvements, and bug fixes every month. Please subscribe to our Azure SDK Blog RSS Feed to get notified when a new release is available.

You can find links to packages, code, and docs on our Azure SDK Releases page.

Release Highlights

  • Azure Identity GA release with new Developer Credential types, logging enhancements, proactive token refresh, and authority host support. Read more in our blog post: Azure SDK: What’s new in the Azure Identity August 2020 General Availability Release
  • Azure Cognitive Search SDK for .NET added FieldBuilder to help easily build a search index from a model type.
  • Added ObjectSerializer and JsonSerializer APIs to support pluggable serialization within SDKs.
  • Added support for Key Vault service version 7.1 for Keys, Secrets, and Certificates

Release Notes

Azure SDK Blog Contributions

We are open to Azure SDK blog contributions and invite you to be a guest blogger. Please contact us at azsdkblog@microsoft.com with your topic and we’ll get you setup.

#azure sdk #.net #java #javascript #python #release #sdk #typescript