Promise Extensions for JavaScript (prex)
Asynchronous coordination for JavaScript and TypeScript.
This library contains a number of coordination primitives to assist in asynchronous application development in JavaScript and TypeScript. This includes useful additions for building complex asynchronous logic including:
- Cancellation [Sample, API Reference]
- Coordination [Sample, API Reference]
- Scheduling [Sample, API Reference]
Installing
For the latest version:
npm install prex
Documentation
Samples
Cancellation
API Reference: Cancellation
The CancellationTokenSource and CancellationToken primitives allow you to create asynchronous operations that can be canceled externally. The following is an example of a function used to download a file asynchronously that can be canceled:
;;;
Coordination
API Reference: Coordination
A Semaphore can be used to protect access to a critical section of your code when you must limit access across multiple async operations. The following is an example of two functions which both need exclusive access to a single resource but could possibly be preempted when suspended while awaiting an asynchronous operation:
; ; declare ;
A Barrier can be used to coordinate complex async operations:
; ;
Scheduling
API Reference: Scheduling
An AsyncQueue is a useful primitive for scheduling asynchronous work:
; ;
License
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0.
See LICENSE file in the project root for details.