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

apolling

v1.1.2

Published

一个有效方便简单的借助rxjs实现的轮询状态机

Downloads

6

Readme

使用

/**
 * 建立定格时间的轮询 ,通过running开始执行,其回调表明每次执行的结果,会等待接口resolve,
 * 并设置结束条件pollingCondition与副作用effectHook(不影响轮询结果),当
 * pollingCondition 回调返回false时代表轮询任务完成执行finishedHook的回调。否则会一直执行并且会使用
 * effectHook 回调。
 * 当你对effectHook回调的返回结果数据不满意则可以通过forceChangeResponse来更改,
 * 区别在于 forceChangeResponse 会更改每次流的传递数据。而effectHook不会。
 * 顺序为 forceChangeResponse -> effectHook.即effectHook的参数被forceChangeResponse返回值影响
 *
 * 事件结束后调用over()销毁轮询实例,注意 over不会引起finishedHook回调!!!
 * finishedHook 表明整个轮询流程结束。不算在流程内,它更像是一个标志,即 整个流程从开始一直到pollingCondition返回false为止一直不被人为over的一个阶段。
 * 反之 forceChangeResponse 与 effectHook 与running 则对应流程的过程 (开始->过程ing)当其中存在异常后则结束流程不再轮询,此时finishedHook会被调用
 * 当catchReject被调用后,forceChangeResponse 与 effectHook 与running 则对应流程的过程的异常将会被捕获,
 *
 */
//创建 构造函数参数为 (间隔时间,时效单位秒)
new Polling(1, 30000000)
    //结束条件,false时结束
    .pollingCondition(i => true)
    .finishedHook(() => {
        //结束回调
        console.log('finished')
    })
    .forceChangeResponse(r => {
        //更改流处理内容,参数r为每次轮询的结果,返回值会合并进流中 同map
        return {}
    })
    //暂停请求,不中止流程。return true 时不再发送请求但会持续执行。pre为上一个执行成功的来自请求的数据
    .pauseRequest((pre)=>{
        console.log(pre)
      //  return true
    })
    //捕获错误信息,它会捕获源自effectHook 与 forceChangeResponse 与running回调返回的接口结果 的错误信息。不对finishedHook捕获
    .catchReject(err => {
        console.log(err)
    })
    //轮询副作用回调,不影响流程结果同tap
    .effectHook((newValue, oldValue) => {
        // ...
        console.log({newValue, oldValue}, 'effect')
    })
    //开启轮询 回调返回某个接口从处理
    .running(() => axios.get('xxxx/xxxx/xxxx'))

//销毁
new Polling(1).over()

download

  • npm i apolling

FQ:

email:[email protected]