How to use the deferred.apply function in deferred

To help you get started, we’ve selected a few deferred examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github joelewis / hnlive / index.js View on Github external
'Saturday': null
    };

    var today = new Date().setHours(0, 0, 0, 0);
    today = moment(today);
    var lastSaturday = today.clone().startOf('week').subtract(1, 'day');
    for (var i=6; i>=0; i--) {
        var day = lastSaturday.clone().subtract(i, 'days');
        var dateString = day.format('YYYY-MM-DD');
        var querySql = "SELECT * FROM datapoints where DATE(time) = DATE('') ORDER BY time desc"
            .replace(/\/g, dateString);
        
        promises.push(sequelize.query(querySql, {model: DataPoint}))
    }
    
    deferred.apply(deferred, promises).then(function() {
        var results = arguments[0];
        var resp = {};
        
        _.each(results, function(dps) {
            var dps = smoothenData(dps);
            var avg = dps.map(function(dp) {
                return dp.variance
            }).reduce(function(prev, next) {
                return prev + next;
            }) / dps.length;
            var day = moment(dps[0].time).format('dddd');
            resp[day] = {average: avg};
        });
        dfd.resolve(resp);
    }).catch(function(){
        dfd.resolve();
github joelewis / hnlive / startcron.js View on Github external
allRequestsSent.promise.then(function(requests) {
                deferred.apply(deferred, requests).then(function() {
                    var stories = arguments[0];

                    var diff = false; 
                    
                    var currentIds = stories.map(function(story) {
                        return story.id;
                    });
                    
                    var arrdiff = arrayDiff(prevStories, currentIds);
                    if (prevStories.length && (arrdiff.insertions.length || arrdiff.deletions.length)) {
                        diff = true;
                    }

                    var totalScore = stories.map(function(story) {
                        var score = story.score + story.descendants;
                        return  score ? score : 0;

deferred

Modular and fast Promises implementation

ISC
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis