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

async-queued

v0.1.3

Published

Simple library to use JS generators with runner function.

Downloads

11

Readme

Async queue for processing data

~96% code coverage ✨

Zero dependencies ✨

Installation and Usage

ES2018 via npm

npm install async-queued
import { CreateAsyncQueue } from 'async-queued'

const queue = new CreateAsyncQueue((value: string) => value, ['1', '2', '3'])
await queue.run()

or if you want to transform every item after queue iteration:

import { CreateAsyncQueue } from 'async-queued'

const queue = new CreateAsyncQueue((value: string) => {
  ...you can do anything with passed value (value from entry array)
  return value
}, ['1', '2', '3'])
await queue.run((item) => {
  ...do all with iteration item
})

Documentation

You can see sample usage in Installation and Usage heading, but this library do more. So the simple example with extended function here:

const queue = new CreateAsyncQueue((value: string) => value, ['1', '2', '3'])
await queue.run()

queue.push(['3', '2', '1'])

queue.run()
...

...

queue.stop()
...

...
await queue.resume()

queue.getResultedData()

If you want to pass function with multiple arguments, you can:

const queue = new CreateAsyncQueue(
  (first: string, second: number) => first + second,
  [
    ['1', 1],
    ['2', 2],
  ],
)
await queue.run()

If you want to control, log or transform every queue item after awaiting, you can pass function to run:

const queue = new CreateAsyncQueue((value: string) => value, ['1', '2', '3'])
await queue.run((item) => {
  ...do with item everything
})

it will be invoked on every iteration.

Also, if you invoke run function second time and don't want to invoke previous function passed, you can suppress this:

const queue = new CreateAsyncQueue((value: string) => value, ['1', '2', '3'])
await queue.run((item) => {
  ...
})

...

await queue.run(null, false)

just pass the second argument as false to suppress invocation

API

Stop

Stop function that stopping all future Promises, but not current.

/**
 * @returns CreateAsyncQueue instance
 */
queue.stop()

Resume

Resume function that resume current queue.

/**
 * @returns CreateAsyncQueue instance
 */
queue.resume()

Push

Push function that push values to current queue.

/**
 * @entry Array of { values }
 * @returns CreateAsyncQueue instance
 */
queue.push([1, 2, 3])

resetAll

resetAll function that reset queue and set queue data.

/**
 * @entry Array of { values }
 * @returns CreateAsyncQueue instance
 */
queue.resetAll([1, 2, 3])

getResultedData

getResultedData function that returns data after the passed iteration, which could be changed.

/**
 * @returns Array of { values }
 */
queue.getResultedData()

getQueueData

getQueueData function that returns data to current queue, that need to be processed.

/**
 * @returns Array of { values }
 */
queue.getQueueData()

getProcessedData

getProcessedData function that returns data that already processed, but not resulted.

/**
 * @returns Array of { values }
 */
queue.getProcessedData()

Couple words about Typescript

If we providing types, it could be easy to queue:

const iterationFn = (value: string) => value
/**
 * value: string -> we have only 1 way how to pass entry value array it is a Array<string>
 */
const queue = new CreateAsyncQueue(iterationFn, ['1', '2', '3'])
await queue.run()
const iterationFn = (value: boolean) => value
/**
 * value: boolean -> we have only 1 way how to pass entry value array it is a Array<boolean>
 */
const queue = new CreateAsyncQueue(iterationFn, [true, false])
await queue.run()
const iterationFn = (value: boolean, secondValue: number) => value
/**
 * value: [boolean, number] -> we have only 1 way how to pass entry value array it is a Array<[boolean,number]>
 */
const queue = new CreateAsyncQueue(iterationFn, [
  [true, 1],
  [false, 2],
])
await queue.run()

it also works with partial arguments

const iterationFn = (value: boolean, secondValue?: number) => value
/**
 * value: [boolean, number] -> we have only 1 way how to pass entry value array
 * it is a Array<[boolean,number]> or Array<[boolean]>
 */
const queue = new CreateAsyncQueue(iterationFn, [[true, 1], [false]])
await queue.run()

Goals

  • Smaller overall bundles sizes
  • Provide better performance than solutions with Promise.all or smth like that
  • Remove Promise all for awaiting iterable data

Building/Testing

  • yarn compile build everything
  • yarn serve run locally
  • yarn tests run tests