New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

kill-async

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kill-async

杀死异步,逃离async,await地狱

latest
npmnpm
Version
0.0.3
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

杀死烦人的异步(kill-async)

介绍

众所周知,js是一门单线程语言,一次异步,处处异步,但有了node后,这门语言变开始走向了新的一个阶梯。可以使用多线程,多进程等!

工作原理: 本包就是利用了多进程的同步函数,使得异步变为同步,参考文献:点击访问

使用方法

// 您需要将要运行的内容传入即可
//例如axios请求(good)
const killAsync = require('kill-async')
var js = `
const axios = require('axios');
 axios('http://httpbin.org/ip').then(res => {
    if (res.data) {
      console.log(res.data);
    }
  }).catch(err=>{
    console.log(err);
  });
`
var data = killAsync(js)
console.log(data);
//bad
const killAsync = require('kill-async')
function js(){
  const axios = require('axios');
 axios('http://httpbin.org/ip').then(res => {
    if (res.data) {
      console.log(res.data);
    }
  }).catch(err=>{
    console.log(err);
  });
}
var data = killAsync(js())
console.log(data);

Keywords

async

FAQs

Package last updated on 21 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts