Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asynctsync

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asynctsync

async waterfall

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

async2sync

将异步数据请求按publish的顺序串联,中间有数据传递,形成瀑布流,并且可以设置初始参数

引入

方法1:

因为没有发布的npm,是以npm私包存放的,so以私包方式加载
npm install git+ssh://git@github.com:canwhite/async2sync.git
使用的时候可以自己在git上fork一下,同样格式去调用安装

方法2:

直接下zip包到本地加载

使用

import AsyncWaterfall from 'async2sync'
//定义初始传入的参数
let queue = new AsyncWaterfall(['name']);
console.time('cost6');

//发布,因为是瀑布流,resolve的值可以往下传递
queue.publish_promise('1',function(name){
   return new Promise(function(resolve,reject){
       setTimeout(function(){
           console.log(name, 1);
           resolve('1');
 
       },1000)
   });
});
queue.publish_promise('2',function(data){
    return new Promise(function(resolve,reject){
        setTimeout(function(){
            console.log('this is 2 , get data form 1:', data);
            resolve('2')
        },2000)
    });
});
queue.publish_promise('3',function(data){
    return new Promise(function(resolve,reject){
        setTimeout(function(){
            console.log('this is 3 , get data from 2:',data);
            resolve()
        },3000)
    });
});
//订阅,传入初始参数,按顺序执行异步操作
queue.promise('series promise').then(res=>{
    console.log(res);
    console.timeEnd('cost6');
}).catch((err)=>{
    console.log('error',err);
    console.timeEnd('cost6');
});

/*
输出:
series promise 1 Home.vue:26
this is 2 , get data form 1: 1 Home.vue:35
this is 3 , get data from 2: 2 Home.vue:43
2 Home.vue:50
cost6:6007 毫秒 - 倒计时结束


*/


FAQs

Package last updated on 27 May 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc