deferred.gate and emitting progress

42 views
Skip to first unread message

Yury Michurin

unread,
Jun 5, 2013, 11:31:15 AM6/5/13
to defer...@googlegroups.com
Hi,
I'm trying to emit progress while using gate like that:
/*global require, setInterval, clearInterval, console*/
var deferred = require('deferred'),
    async = function () {
        var def = deferred(),
            ct = 10,
            intervalId = setInterval(function () {
                if (!ct) {
                    clearInterval(intervalId);
                    def.resolve();
                } else {
                    console.log('async emiting', ct);
                    def.promise.emit('progress', ct);
                    ct--;
                }
            }, 100);
        
        return def.promise;
    },
    asyncGated = deferred.gate(async, 2);


var p = asyncGated(),
    p2 = asyncGated(),
    p3 = asyncGated();

p.on('progress', function (prg) { console.log("p ", prg); });
p2.on('progress', function (prg) { console.log("p2 ", prg); });
p3.on('progress', function (prg) { console.log("p3 ", prg); });

p and p2 executed immidatly and get the progress event ok, however p3 does not =\
what am I missing?

Thanks in advance,
Yury.

Mariusz Nowak

unread,
Jun 5, 2013, 2:39:04 PM6/5/13
to defer...@googlegroups.com
Yury,

Plain reason is that promise returned from gate, is different from promise returned by function if invocation is put on hold, and events are not propagated between promises.

Indeed that's not expected limitation, so I decided to unify events handling for counterpart promises in gate, please update to v0.6.5 to experience new behavior.

Hope that solves your issue.

Mariusz

Yury Michurin

unread,
Jun 6, 2013, 6:49:15 AM6/6/13
to defer...@googlegroups.com
Thanks for the quick response =)
0.6.5 Works grate here!
Reply all
Reply to author
Forward
0 new messages