ide / Mux
Licence: mit
Creates a promise that waits for the promises in nested data structures and resolves to data structures of the same form. It recursively traverses the input data structure and multiplexes its promises.
Stars: ✭ 153
Programming Languages
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Mux
Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (-16.99%)
Mutual labels: promise
Unityfx.async
Asynchronous operations (promises) for Unity3d.
Stars: ✭ 143 (-6.54%)
Mutual labels: promise
Kitchen Async
A Promise library for ClojureScript, or a poor man's core.async
Stars: ✭ 128 (-16.34%)
Mutual labels: promise
Poloniex Api Node
Poloniex API client for REST and WebSocket API
Stars: ✭ 138 (-9.8%)
Mutual labels: promise
Sieppari
Small, fast, and complete interceptor library for Clojure/Script
Stars: ✭ 133 (-13.07%)
Mutual labels: promise
Functional Promises
Write code like a story w/ a powerful Fluent (function chaining) API
Stars: ✭ 141 (-7.84%)
Mutual labels: promise
Image Promise
🎑🤞 Load one or more images, return a promise. Tiny, browser-only, no dependencies.
Stars: ✭ 129 (-15.69%)
Mutual labels: promise
Node Stratum
Stratum protocol server and client for Node.js
Stars: ✭ 129 (-15.69%)
Mutual labels: promise
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (-5.88%)
Mutual labels: promise
mux
A simple and convenient function that resolves promises in data structures like arrays, objects, Maps, and Sets
What is mux?
Mux is a function that multiplexes promises in nested data structures and resolves them like this:
await mux({
a: asyncFunction1(),
b: asyncFunction2(),
});
// Result:
{
a: result1,
b: result2,
}
Installing mux
yarn add @expo/mux
And import it like this:
import mux from '@expo/mux';
More examples
You can also pass in deeply nested data structures like this:
await mux({
a: {
b: asyncFunction1(),
},
});
// Result:
{
a: {
b: result1,
},
}
Mux supports several standard JavaScript data structures:
await mux(new Set([
asyncFunction1(),
asyncFunction2(),
]));
// Result:
new Set([
result1,
result2,
])
And if your promises themselves result in data structures, mux will recurse into them and resolve the nested promises.
await mux([
Promise.resolve({
a: asyncFunction1(),
}),
]);
// Result:
[
{
a: result1,
},
]
Check out the test suite for even more examples.
Interesting use cases
If you've discovered a particularly interesting way to use mux, add it here and send a PR to share it.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].