javascript - Using Promises upon different parts of object -
i'm working on program has main object object called glob,.
in first phase of program , need files in folder using async function , assign result files property, i'm using promise:
glob.files = new promise (resolve, reject) { asyncfunc(args, function(result) { resolve(result); }); }
then, in older phases, need access glob files, need make cpu intensive work, i'm using async.eachlimit limit number of concurrencies, because of this, whole glob become promise:
new promise (resolve, reject) { glob.files.then(function(files) { var temporary1 = []; var temporary2 = []; async.eachlimit(files, 5, function(file, callback) { // here // // temporary1.push(file); or temporary2.push(file); }, function(error, files) { // work temporary1 , temporary2 variable here, delete unnecessary pieces , reassign glob.files; // reassign glob.files glob.files = temporary1.concat(temporary2); // resolve passing glob resolve(glob); }); }); }
now able access need call glob.then, because it's promise.
glob.then(function(glob) { // ok! :) });
everything working ok, i'm not having problem, feel i'm doing wrong...
Comments
Post a Comment