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

miniprogram-queue

v4.5.1

Published

Queue Management for Wechat MiniProgram

Downloads

188

Readme

miniprogram-queue npm version

Queue Package for MiniProgram API

小程序底层操作队列化(wx.request, wx.downloadFile,wx.uploadFile)

miniprogram-network默认队列实现

Features:

Install(安装)

npm i miniprogram-queue

Usage(使用)

import {WxQueue} from 'miniprogram-queue';
//创建请求队列
const requestQueue = new WxQueue(wx.request,10);
// const uploadQueue = new WxQueue(wx.uploadFile,10);
// const downloadQueue = new WxQueue(wx.downloadFile,10);

// 发送请求
const task = requestQueue.push({
    url:'https://github.com/NewFuture/miniprogram-network/'
});

// task.abort() 可取消操作

API

参数

与官网API参数兼容 支持 扩展参数:

  • onProgressUpdate 进度回调函数
  • onHeadersReceived 响应头回调函数
  • jump (默认false)是否插队
  • timestamp (默认false) 是否记录时间戳,是则complete回调中会包含 一个time字段
{
    send: number,
    response: number
}

兼容API

同时 downloadFileuploadFile 支持通过process 参数 之间设置进度回调

jump (插队)

//第二个参数为true时优先级最高
requestQueue.push({
    url:'https://github.com/',
    jump:true,//插队
});

Abort (取消操作)

所有操作返回一个Task对象,可取消操作

注意: 和官方API一致 取消时依然会执行complete(如果配置了)

  • 自动注入方式
var task = wx.request(obj);
task.abort();
  • 手动push
var task = queue.push(obj);
task.abort();

Progress (进度支持)

  • DownloadTask.onProgressUpdate(function callback)
  • UploadTask.onProgressUpdate(function callback)

小程序onProgressUpdateAPI的接口,设计上不太合理, 这个接口放在请求发生时更合适,而非在Task创建后。

此处保留了对onProgressUpdate的兼容适配,同时提供了可通过参数(progress)传入的方法


const task =uploadQueue.push({
    // 其他参数
    onProgressUpdate:processCallback// callback function
    onHeadersReceived:console.log
});
// function processCallback(progress,currentBytes,totalBytes){}
// obj update object
const task = wx.uploadFile(obj);
// 保留原生调用方式支持
task.onProgressUpdate(processCallback); // callback function
// function processCallback(progress,currentBytes,totalBytes){}