
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
simple-await
Advanced tools
Executing async function with simple error handling. Returns object with data and error.
Execute async function with simple error handling. Returns object with data and error.
yarn add simple-await
import wait from 'simple-await';
function rejecter() {
return Promise.reject(new Error("my new error"))
}
function solver(): Promise<{ name: string }> {
return Promise.resolve({ name: "John" })
}
async function withFetch() {
const { data, error } = await wait<object, string>(fetch('http://httpstat.us/503'));
console.log(data, error) // undefined, Failed to fetch
}
async function solve() {
const { data, error } = await wait<{ name: string }, string>(solver());
console.log(data, error) // { name: "John" }, undefined
}
async function reject() {
const { data: result, error: cause } = await wait(rejecter());
console.log(result, cause) // undefined, my new error
}
Simple-await uses Promise.allSettled()
under the hood. Please check MDN for browser compatibility. Also, note that tsconfig
configured to target es2020. Please let me know if you need to change it or support some older broswer versions.
MIT
FAQs
Executing async function with simple error handling. Returns object with data and error.
We found that simple-await demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.