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-queue-progress

v1.1.1

Published

一个有执行进度展示的异步任务队列

Downloads

3

Readme

简介

这是一个有执行进度展示的异步任务队列,常用于批量抓取接口的任务执行和进度展示等... 借鉴于 single-line-log 库,在原基础上进行调整并封装了异步任务队列及执行进度展示

示例

const AsyncQueueProgress = require('async-queue-progress');
const taskQueue = AsyncQueueProgress({
  asyncMax: 5,
});

main();

function main() {
  taskQueue.progressBar.describe('加载中...');
  for (let i = 0; i < 100; i += 1) {
    taskQueue.add(task, `describe-${i}...`, `title-${i}:`, `data-${i}`);
  }

  taskQueue.start();
}

function task(data, index) {
  return new Promise((resolve) => {
    // 模拟完成任务
    setTimeout(() => {
      console.log(data);
      if (index === 30) {
        taskQueue.stop().then(() => {
          console.log('[stop ] end', new Date());
        });
      }
      resolve();
    }, 1000 * Math.random());
  });
}

文档

TaskQueue

  • progressBarProgressBar - 当前队列的进度条对象

  • config(opts: TaskQueue.Options) => void - 配置

  • resetasync () => void - 重置

  • clearasync (opts: TaskQueue.Options) => void - 清空

    • opts:配置项
  • add(promise, describe, title, data) => void - 添加一个任务

    • promise(data, index: Number) => Promise | async (data, index: Number) => void - 要执行的任务
    • describeString - 执行时显示的描述
    • titleString - 执行时显示的标题
    • dataString - 数据
  • start() => Promise - 开始/继续 执行任务

  • stop() => Promise - 暂停 执行任务

  • index() => Number - 当前执行的任务的下标

  • length() => Number -任务队列的长度

  • isStop() => Boolean - 是否未开始

  • isWillComplete() => Boolean - 是否即将完成

  • isComplete() => Boolean - 是否已经完成

TaskQueue.Options

  • asyncMaxNumber - 任务最大异步执行数,默认为 3

  • logBoolean - 是否显示日志,默认为 true

  • onComplete(isComplete: Boolean) => void - 完成回调,默认为 null

    • isCompleteBoolean - 是否完全的完成了,判断标准 index 等于 length
  • onStop(index: Number) => void - 暂停回调,默认为 null

    • indexNumber - 暂停时当前项的下标
  • onError(error: Error, task: Task) => void - 报错回调,默认为 null

    • errorError - 错误内容
    • taskTask - 报错的任务

TaskQueue.Task

  • promise(data, index: Number) => Promise | async (data, index: Number) => void - 要执行的任务

  • describeString - 执行时显示的描述

  • titleString - 执行时显示的标题

  • dataString - 数据

ProgressBar

  • config(opts: ProgressBar.Options) => this - 配置

  • title(val: String) => this - 设置标题

  • describe(val: String) => this - 设置描述

  • add(val: Number) => this - 增加进度值

    • valNumber - 要增加的进度值,默认 1
  • value(val: Number, append: Boolean) => this - 设置/增加 进度值

    • valNumber - 要 设置/增加 的进度值,默认 1
    • appendBoolean - false 设置,true 增加
  • total(val: Number, append: Boolean) => this - 设置/增加 总数值

    • valNumber - 要 设置/增加 的总数值,默认1
    • appendBoolean - false 设置,true 增加
  • isFull() => Boolean - 进度是否是 100%

  • render(force: Boolean) => void - 刷新进度条

    • forceBoolean - 是否强行刷新,否则按 Options.renderRate ms 刷新一次
  • quit() => void - 结束这个进度条,下次刷新绘制新的进度条

ProgressBar.Options

  • valueCharString - 进度填充字符,默认为 '#'

  • emptyCharString - 进度空白字符,默认为 ' '

  • lengthString - 进度条长度,默认为 50

  • titleString - 标题,默认为 'load:'

  • describeString - 描述,默认为 ''

  • totalNumber - 总值,默认为 0

  • valueNumber - 进度值,默认为 0

  • renderRateNumber - 刷新频率:ms/次,默认为 16

  • format(data: PercentData) => String - 将进度数据转换为字符串以显示,默认为:

    function format(data) {
      let title = `${data.title} ${(100 * data.percent).toFixed(3).substr(0, 5)}%`;
      if (data.describe) title = `${data.describe}\n${title}`;
      return `${title} [${data.cells}] [${data.percent * data.total}/${data.total}]\n`;
    },