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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@amaoaaaaa/safe-poll

v2.0.2

Published

A safe polling hook for Vue 3 dashboards. Polling will never stop because of async errors.

Readme

@amaoaaaaa/safe-poll

安全轮询 Hook,保证异步函数抛出错误不会中断轮询。

基于 VueUse 的 useTimeoutPoll 封装,提供自动启动、立即回调、错误处理等功能。

安装

npm install @amaoaaaaa/safe-poll

使用

import { usePoll } from "@amaoaaaaa/safe-poll";

const { pause, resume } = usePoll(
    async () => {
        const res = await fetchData(); // 这里报错也没事
        console.log(res);
    },
    3000,
    {
        onError(err) {
            console.error("poll failed", err);
        },
    },
);

API

usePoll(fn, interval, options?)

注册一个安全轮询任务。

参数

| 参数 | 类型 | 默认值 | 说明 | | ---------- | ----------------------- | ---------------------------------------------- | ---------------- | | fn | () => Awaitable<void> | — | 轮询函数,每次轮询执行的操作 | | interval | number | — | 轮询间隔,单位毫秒 | | options | UsePollOptions | { immediate: true, immediateCallback: true } | 配置项 |


UsePollOptions

| 属性 | 类型 | 默认值 | 说明 | | ------------------- | ------------------------ | ------ | ------------------------------------------------------- | | immediate | boolean | true | 是否在 hook 创建时立即启动轮询。如果为 false,需要手动调用 resume() 才会开始 | | immediateCallback | boolean | true | 是否在启动轮询时立即执行一次回调。配合 immediate 使用,决定是否在初始化时立刻调用 fn() | | onError | (err: unknown) => void | — | 当轮询函数抛出错误时的回调,用于统一处理异常,保证轮询不会中断 |


返回值

  • 返回 Pausable 对象(来自 VueUse):
interface Pausable {
    /**
     * 当前实例是否处于激活状态
     * - true:轮询或定时器正在运行
     * - false:已暂停
     */
    isActive: Readonly<ShallowRef<boolean>>;

    /**
     * 暂停轮询 / 定时器
     * 调用后 effect 将停止执行,直到 resume() 被调用
     */
    pause: Fn;

    /**
     * 恢复轮询 / 定时器
     * 调用后 effect 将继续按原间隔执行
     */
    resume: Fn;
}
  • 可通过 pause() 暂停轮询,通过 resume() 恢复轮询。