A
A
amorphine2016-11-11 14:30:33
Node.js
amorphine, 2016-11-11 14:30:33

Event-Driven Style Code - How to Queue Jobs?

There is a code for generating critical css:

module.exports = function(gulp, plugins) {
    return function () {
        var critical = require('critical'),
            settings = require("./settings.js"),
            urls = settings.urls,
            dimensions = settings.dimensions;

        dimensions.forEach(function(dimension){
            urls.forEach(function(entry){
                critical.generate({
                    src: settings.base_url + entry.url,
                    dest: settings.dest_folder + dimension.prefix + entry.name + '.css',
                    minify: true,
                    ignore: ['.big-header-wrapper', 'header.small'],
                    width: dimension.width,
                    height: dimension.height
                });
            });
        });
    };
}

It immediately creates dimensions.lenght * urls.length tasks and puts them into processing. How can I arrange the code so that the tasks go in turn: the next one starts as soon as the previous one finishes?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-11-14
@amorphine

Instead of async, it is now better to use the built-in Promise class in es6.
https://www.youtube.com/watch?v=vNEDPtVchfw&index=...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question