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

eliminate-async

v1.0.0

Published

<p align="center">eliminate-async</p>

Downloads

7

Readme

github: https://github.com/gengfanbin/eliminate-async

什么是javascript的异步传染性

JavaScript中的异步传染性是一个在编程中常见的现象,它指的是当一个函数内部包含异步操作(如使用Promise、async/await等)时,这种异步特性会传递给调用它的函数,以及调用这些函数的函数,依次传递下去。这可能会导致整个调用链上的函数都需要处理异步操作,从而增加了代码的复杂性和维护难度。

eliminate-async做了什么

eliminate-async是一个JavaScript库,它使用rust创建一个JavaScript沙盒环境,使当前函数脱离当前文档流,在沙盒环境中执行,从而消除函数的异步特征,进而消除异步传染性问题。

eliminate-async的缺点

1:eliminate-async它需要创建一个JavaScript沙盒环境,这可能会带来一些性能上的开销。同时,由于沙盒环境与当前文档流隔离,因此无法访问文档流的上下文。后续版本会优先解决这个问题。 2:由于跨语言调用的原因,rust的类型系统无法完全保证与JavaScript类型系统的兼容性,因此在使用eliminate-async时,需要注意类型转换的问题。第一个大版本的eliminate-async会强制限制函数入参和出参类型必须能够被JSON格式化,以这种取巧的方式绕过类型匹配的问题。后续会尝试完善类型系统。

eliminate-async的使用方式

eliminate-async的使用方式非常简单,只需要将一个异步函数传递给createHandler函数,即可创建一个同步函数。然后,可以使用execHandler函数来执行这个同步函数,就像执行普通的同步函数一样。可以通过removeHandler函数来移除这个同步函数并释放资源。 如果需要立即执行异步函数,可以使用syncExec函数。

立即执行与创建句柄的区别在于立即执行的函数不会创建句柄,因此是一次性的,而创建句柄的函数可以多次执行。同时,立即执行函数在每次执行时都会创建一个新的沙盒环境,而创建句柄的函数则会在第一次创建沙盒环境后复用这个沙盒环境,从而提高性能。

import { createHandler, execHandler, removeHandler, syncExec } from 'eliminate-async';

// 创建一个异步函数
const asyncFunc = async () => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve('Hello, eliminate-async!');
    }, 1000);
  });
};

// 创建一个同步函数
let createResult = createHandler(asyncFunc);
let syncFunc
if (createResult.code == 0) { // 成功时返回code码为0
  syncFunc = createResult.result;
}

// 执行同步函数
let res = execHandler(syncFunc, arg1, arg2, ...); // 输出: Hello, eliminate-async!

// 移除同步函数
removeHandler(syncFunc);

// 立即执行异步函数的方式
console.log(syncExec(asyncFunc, arg1, arg2, ...)); // 输出: Hello, eliminate-async!

eliminate-async的安装

npm install eliminate-async

如果发现它存在的一些缺陷,请提Iusses!!!。