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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -