码迷,mamicode.com
首页 > 其他好文 > 详细

async异步流程控制神器

时间:2019-06-17 01:00:58      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:directly   oba   play   ring   com   The   show   ESS   set   

async

https://www.npmjs.com/package/async

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install async, it can also be used directly in the browser. A ESM version is included in the main async package that should automatically be used with compatible bundlers such as Webpack and Rollup.

A pure ESM version of Async is available as async-es.

For Documentation, visit https://caolan.github.io/async/

For Async v1.5.x documentation, go HERE

 

API

https://github.com/caolan/async/blob/v1.5.2/README.md#waterfall

Control Flow

 

动画

https://github.com/fanqingsong/async_animation

index.js

import ‘./css/style.css‘;
import ‘./sass/index.scss‘;

var async = require("async");

window.onload = () => {
    let salutions = document.querySelectorAll("#salutions>div");
    for(let one of salutions){
        one.style.display = "none";
    }

    async.waterfall([
        function(callback) {
            salutions[0].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[1].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[2].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            salutions[3].style.display = "flex";

            setTimeout(callback, 1000);
        },
        function(callback) {
            callback(null);
        }
    ], function (err, result) {
        // result now equals ‘done‘
    });
};

 

html

    <div class="c-Sticky">
        <div class="c-Sticky-bd">
            <h1 style="text-align: center;">Async Show</h1>

            <div id="salutions" style="font-size: xx-large; color:blue;  display: flex; justify-content:center;">
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: steelblue"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: antiquewhite"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: azure"></div>
                <div style="display:flex;width:200px;height:200px; justify-content:center;align-items: center ; margin: 5px; background-color: beige"></div>
            </div>

        </div>
    </div>

 

效果

 显示从左到右每个一秒显示一个方块字。

技术图片

 

async异步流程控制神器

标签:directly   oba   play   ring   com   The   show   ESS   set   

原文地址:https://www.cnblogs.com/lightsong/p/11037493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!