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

@navidjalali/io

v1.1.1

Published

A simple IO monad.

Downloads

4

Readme

🍉 IO

A small library that makes promises less eager 🥔

IO<A> is a lightweight wrapper around () => Promise<A> with some useful combinators.

🔧 Installation

npm install @navidjalali/io

⚡️ How to make an IO

You can make a new IO using one of the following ways:

🏋🏻‍♂️ Lifting a pure value into an IO:

You can make a successful or failed IO out of a pure value.

IO.succeed(value)
IO.fail(error)
IO.fromNull(maybeNull)
IO.fromUndefined(maybeUndefined)
👷🏻‍♂️ Using the constructor:

This is very similar to creating a normal Promise.

new IO<A>((resolve, reject) => {
    // ...
})
🦆 From a thunk that returns a promise

Any promise can be wrapped into an IO.

IO.fromThunk(() => fetch('/api/v1/posts'))
🍩 From a function

Exceptions thrown by the function will be lifted into failures.

const unsafeFunction = () => {
    // Unsafe code
}

IO.fromThunkSync(unsafeFunction)

🤔 How to evaluate an IO?

Simply call .run(). This will create a normal Promise.

❓ Polling

Any IO that will return some Union type A | InProgress can be polled using IO.poll. This will rerun the IO until it succeeds with a result of type A.

const checkProgress: IO<Result | InProgress> = IO.fromThunk(
    () => fetch('/api/v1/progress/poll')
).flatMap(_ => _.json())
const result: IO<Result> = IO.poll(checkProgress, 100)

⏰ Scheduling

You can schedule an IO to run later using the scheduleOnce and scheduleForever combinators. You can also make more complicated scheduling logic yourself using IO.sleep and recursion.

🔁 Retries

You can retry an IO using a RetryPolicy. Currently you can only pick between Spaced and ExponentialWithBackoff

IO.fromThunk(() => fetch('/api/v1/posts'))
    .retry(RetryPolicies.spaced(100, 3))

⏳ Timeout

You can effectively get a rejection if your effect runs longer than a specified period using the timeout combinator but please keep in mind that this WILL NOT cancel the Promise created from running this effect or interrupt its finalizers. Hopefully I will make this behaviour better soon.

🌈 More!

There's more you can do. Feel free to check the code, and contribute if you find a new usecase that can be covered!