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

yacol

v1.1.2

Published

[![CircleCI](https://circleci.com/gh/vacuumlabs/yacol.svg?style=svg)](https://circleci.com/gh/vacuumlabs/yacol)

Downloads

38

Readme

CircleCI

Yet Another COroutine Library with some unique features.

Why this

"... Promises and Futures are sort of lightweight constructs, you know, that are one-night-stands, right? They're just handoffs or call and return scenarios. They can't really model enduring connections. And so they're not actually helpful for this. So it's sugar. I mean, it's good sugar, but I felt like we should put it on a better cake."

Yacol is here to patch behavior of async and await keywords. Typically, your code written with async, await and standard Promisses should work seamlessly with Yacol. With Yacol, you are given better error handling, better termination of dangling promises; futhermore you can kill the asynchronous functions and use async functions' context - similar to (deprecated) domains in node.js. Let's see some examples. First, you can do beautiful error handling such as:

try {
  await asyncFunctionIHaveNoTimeToReviewSoImAffraidOfAsyncErrors()
} catch (err) {
  // yup, all the errors will go here. Even those from not awaited asynchronous functions.
}

Yop, it's that easy. Full example:

async function doThrow() {
  throw new Error('SAD')
}

async function fn() {
  // it doesn't matter, whether we await doThrow or not: when error is throwed, fn ends up errorneous
  doThrow()
}

async function main() {
  try {
    await fn() // only in try-catch block the await must not be forgotten
  } catch (e) {
    console.log('Unlike with standard promises, error will be caught')
  }
}

main()

This is, how kill works:

import {Promise} from 'bluebird'

async function test() {
  const time = 2500 // feels like forever
  await Promise.delay(time)
  console.log('this will print if time < 1000')
}

async function runTestForAtMost1Sec() {
  const testCor = test(); // start async function, but don't wait for it
  (async () => { // start second coroutine with purpose only to kill the first one after given timeout
    await Promise.delay(1000)
    kill(testCor)
  })()
}

Context is namespace, which can be read and write by parent coroutine and read by child coroutines. It's similar to node.js (deprecated) domains or Dart zones. You can use it as simple as:

import {context} from 'yacol'

async function contextDemo() {
  context.set('hello', 'world');
  (async () => {
    console.log('if this prints "world", I can read a value from my parent context')
    console.log(context.get('hello'))
  })()
}

contextDemo()

Furthermore, check out examples to see more:

  • how meaningful stacktraces can be
  • how to use with Express
  • messaging features!