1.0.5 • Published 8 years ago

babel-plugin-async-function-time v1.0.5

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

babel-plugin-async-function-time

Travis npm package

A babel plugin of statistical Asynchronous Function Time, containing promise function and asynchronous callback function.

Usage

Install

Using npm:

$ npm install babel-plugin-async-function-time -D

configure in .babelrc(should transfer to json format) or any babel queries:

Usage Example

configure

"plugins": [
    [
        "function-time", {
			// A function that defines the execution time of the logging function, the execution time of the asynchronous function, and the arguments of the original function as arguments to the function
            "report": "(durning, props) => console.log('count:%sms', durning)",
			// The array of promise function names to be logged
            "promise": ["fnNameA"],
			// An array of asynchronous callback function names to be logged
            "async": ["fnNameB"]
        }
    ]
]

code for promise function

var fnNameA = function (str) {
    return new Promise(function(resolve) {
        setTimeout(function() {
            resolve(str);
        }, 200);
    })
};

fnNameA();

// or

function fnNameA (str) {
    return new Promise(function(resolve) {
        setTimeout(function() {
            resolve(str);
        }, 200);
    })
};

fnNameA();

// or

var obj = {
    fnNameA(str) {
        return new Promise(function(resolve) {
            setTimeout(function() {
                resolve(str);
            }, 200);
        })
    }
};

obj.fnNameA();

// count:204ms

code for asynchronous callback function

var fnNameB = function (fb) {
    setTimeout(function() {
        fb();
    }, 200);
};

fnNameB();

// or

function fnNameB (fb) {
    setTimeout(function() {
        fb();
    }, 200);
};

fnNameB();

// or

var obj = {
    fnNameB(fb) {
        setTimeout(function() {
            fb();
        }, 200);
    }
};

obj.fnNameB();

// count:204ms

Changelog

How to Contribute

Anyone and everyone is welcome to contribute to this project. The best way to start is by checking our open issues, submit a new issues or feature request, participate in discussions, upvote or downvote the issues you like or dislike.