meteor.js fiber callback after each

547 views Asked by At

I am trying to call some function AFTER _.each is done... i am trying to do it with fibers. But if you show me how to do it with underscore.js AFTER method i will be happy as well.

For now i have this:

                function doAsyncWork() {
                var fiber = Fiber.current;
                    _.each(myInv.items,function(loopItem,key,list){
                        if (loopItem.itemId == item.shopId) {
                            ownItem = true;
                            countOfOwnItem = loopItem.number;
                        }
                        Fiber.yield();
                    });         
            }

            Fiber(function() {

                doAsyncWork();

            }).run();

And i need to place somewhere fiber.run() as well or? But i dont know where.

Again i want to call some function lets say finished() WHEN THE EACH LOOP is done.

1

There are 1 answers

0
Sean Yang On

I'm also riding on the learning curve of Node.js... but I think this can be a good read up in your case:

http://bjouhier.wordpress.com/2012/03/11/fibers-and-threads-in-node-js-what-for/