npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@thatsmrtalbot/async

v1.0.6

Published

Some async utils

Downloads

7

Readme

Async

Async utilities for typescript

This is a bunch or utils for working with async functions in typescript. All functions can be imported from the package or from their subpackage.

For example:

import or from '@thatsmrtalbot/async/or';
// Is equal to
import {or} from '@thatsmrtalbot/async';

This is usefull when the result is bundled for the web as it reduces unused code.

Utils

all

This is equivilent to Promise.all(). It follows the same syntax as the rest of these utils.

For example:

await all(
    () => repository.deleteUser(username),
    () => repository.deleteProfile(username),
    () => repository.deletePosts(username),
)

or

Or allows you to perform one or more actions until a non null value is returned.

For example:

let user = await or(
    () => repository.getUser(username),
    () => repository.createUser(username),
)

You can also use it to throw errors on null values:

let user = await or(
    () => repository.getUser(username),
    () => { throw new Error("User does not exist") },
)

promisify/promisifyAll

These are the similar to bluebird.promisify and bluebird.promisifyAll, without the additional promise implimentation.

let read = promisify(fs.read)
let fsAsync = promisifyAll(fs)
//read == fsAsync.readAsync

resolver

Resolver is a promise with external methods to resolve and reject.

let resolver = new Resolver<string>()
resolver.resolve("value")

tick

Tick uses setTimeout to defer the execution of a function for a tick.

await tick()

time

Time times the execution of a promise:

let user = await time(
    () => repository.getUser(uid),
    (err, time) => console.log(`Execution took ${time}`)
)

timeout

Timeout allows you to set a time limit for promises to resolve

await timeout(
    () => repository.getUser(uid),
    500,
)

wait

Tick uses setTimeout to wait a specified amount of time:

await wait(500)

array

Some async versions of array utils

let odd = await array([1,2,3,4,5]).filterAsync(async (value, index) => value % 2)
let even = await array([1,2,3,4,5]).mapAsync(async (value, index) => value * 2)
await array([1,2,3,4,5]).forEachAsync(async (value, index) => console.log(value))

dispatch

Dispatch promise values using keys

let dispatcher = new Dispatch();
let promise = dispatcher.next("key");

dispatcher.dispatch("key", "value");

console.log(await promise) // value

retry

Retry function with optional wait time

// Three attempts with 1 second wait
await retry(async () => {
    await doTheThing();
}, 3, 1000)