Last active
August 25, 2017 03:10
-
-
Save aaronksaunders/6245454 to your computer and use it in GitHub Desktop.
Utilizing the Queue Library from Async.js for downloading multiple assets with Appcelerator Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// https://github.com/caolan/async | |
// | |
var async = require('async'); | |
// this function will be called for each array element | |
function process(_url, _processCallback) { | |
// download the file | |
get_file(_url, function(_resp) { | |
if (!_resp.error) { | |
Ti.API.debug('file successfully downloaded ' + _url); | |
} else { | |
Ti.API.error('Error Downloading file ' + _url); | |
Ti.API.error('Error Message ' + _resp.error); | |
} | |
_processCallback(_resp.error); | |
}, null); | |
}; | |
// create the queue | |
var myQueue = async.queue(process, 3); | |
// called when the process is completed | |
myQueue.drain = function() { | |
Ti.API.info('all items have been processed'); | |
}; | |
// START THE PROCESS | |
// processes all of the models in the collection | |
myQueue.push(files_arr, function(_err) { | |
_err && Ti.API.error("error processing queued model " + JSON.stringify(_err)); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment