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

gojy

v0.1.1

Published

Go style control flow with yieldable actions.

Downloads

10

Readme

gojy

Build status Git tag NPM version Code style

GO style control flow in Javascript with Yieldable actions.

gojy is redux style middleware that treats generators as sequential blocking threads. These threads will block on yielded promises and generator - very much like co. gojy however, uses a different concurrency mechanism. Whereas co utilizes arrays and objects, gojy uses the go action. When a go action is yielded a promise is returned that resolves when the go routine completes. This promise can then be yielded at a later point in time to wait for the result.

gojy's concurrency mechanism provides three advantages over co:

  • it's more powerful
  • it doesn't overload objects and arrays so that they can be used as actions
  • it pools goroutines run by an instance of a runner, so that they can all be killed

Installation

$ npm install gojy

Usage

const {run, go, join} = require('gojy')

run(function * () {
  // launch go routine without blocking
  const promise1 = yield go(function * () {
    yield fetch('google.com')
    yield fetch('facebook.com')
  })

  // launch go routine without blocking
  const promise2 = yield go(function * () {
    yield fetch('segment.io')
    yield fetch('mixpanel.io')
  })

  // block
  yield join([promise1, promise2])
})

API

gojy runners

.run(process)

A pure runner with no additional action processing.

  • process - generator to run

Returns: result of generator

.compose(...middleware)

Creates a runner with additional action processing handled by middleware.

  • middleware - redux style middleware

Returns: a gojy runner

.middleware()

Returns: the gojy middleware for use in redux middleware stacks

gojy actions

.go(goroutine)

Launch a goroutine

  • goroutine - goroutine to run

Returns: a promise that resolves on goroutine completion

.kill()

Kill running goroutines launched by runner.

control flow helpers

Helpers for managing control flow.

.join(collection)

Turn collection to a promise and block on it.

  • collection - the promise or collection of promises to block on

Returns: result of promise

implementation:

function * join (collection) {
  return yield toPromise(collection)
}

.forEach(generator, collection)

Async sequential for each.

  • generator - async iteratee
  • collection - collection to iterate over

.map(generator, collection)

Async sequential map.

  • generator - async iteratee
  • collection - collection to iterate over

Returns: mapped collection

.now(collection)

Run collection in parallel and block. Gives you similar behavior to co yielded arrays and objects.

  • collection - the collection of goroutines to run in parallel

Returns result of collection goroutines

implementation:

function * now (collection) {
  return yield join(yield map(go, collection))
}

goisms

Some handy dandy goisms.

.delay(time)

Sleep for time.

.channel()

Simple promise based channel implementation.

Returns: take and put functions for the created channel

.poss(generator)

Go inspired error handling by matthewmueller

Returns: error first array ([err, ...])

.select(cases)

Wait on multiple promises and selects first.

  • cases - array of cases to wait on. Each case is a tuple of the form [promise, cb].

Returns: result cb of fasest promise

Example:

const res = yield select([
  [fetch('google'), _ => 'google is better'],
  [fetch('facebook'), _ => 'facebook is better']
])
console.log(res) // => `google is better`

License

MIT