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

@typeshell/promise

v0.0.5

Published

## install

Downloads

2

Readme

promise-utils

install

npm install @typeshell/promise --save

功能

sleep函数,以及可中断

我可以提供一个 naive版本的

const p = sleep(3000)
setTimeout(() => p.interrupt(), 1000)
await p // one second it will be interrupted

sleep的返回的对象本质是一个可中断的TimeoutPromise

BlockingQueue

import { BlockingQueue, sleep } from "../src"

const waitRandomly = () => sleep(Math.trunc(Math.random() * 100 + 30))

const bq = new BlockingQueue<number>(1)
const n = 10

const producer_main = async () => {
    try {
        for (let i = 0; i < n; ++i) {
            console.log(`put: ${i}`)
            await bq.put(i)
            console.log(`put.result: ${i}`)
            await waitRandomly()
        }
        bq.shutdown()
        console.log("producer_main: shutdown")
    } catch (ex) {
        console.log(ex)
    }
}
producer_main()

const consumer_main = async () => {
    try {
        for (let i = 0; i < n + 10; ++i) {
            console.log(`take.ready: ${i}`)
            // console.log(bq)
            const e = await bq.take()
            console.log(`take.result: ${i} ${JSON.stringify(bq.data)}`)
            await waitRandomly()
        }
        console.log("consumer_main: shutdown")
    } catch (ex) {
        console.log("Get shutdown error")
        console.log(ex)
    }
}
consumer_main()

ExecutorQueue

其它

为什么不做n2n队列

  1. 生产者蜂拥而至,处于await状态,此时其实排在系统内部的队列,本质与我们放在队列排队,无性能区别
  2. 多个生产者在等候,如果无队列化,一定会出现争抢,效率不高

因此 n2n 就用 n->1 以及 1->n 来模拟,避免性能

特性:

  1. n个prodcuer,n个consumer n个prodcuer会

  2. 设置是否blocking

  3. 传入函数,n个兑现

  4. consumer.take

测试

采用长度为1的blockingqueue,非常容易重现死锁的问题