Skip to content

Instantly share code, notes, and snippets.

@astronaughts
Created December 2, 2012 14:07
Show Gist options
  • Save astronaughts/4188863 to your computer and use it in GitHub Desktop.
Save astronaughts/4188863 to your computer and use it in GitHub Desktop.
【3日目】Titanium mobile でも使える非同期処理のためのライブラリ「async.js」
(function(){
var async = require('async');
// 順次処理
async.series([
function(callback){
var message = 'one';
Ti.API.info(message);
callback(null, message);
},
function(callback){
var message = 'two';
Ti.API.info(message);
callback(null, message);
},
], function(err, results){
// results の中身は ['one', 'two']
Ti.API.warn(results);
});
// 並列処理
async.parallel([
function(callback){
var message = 'one';
setTimeout(function(){
Ti.API.info(message);
callback(null, message);
}, 1000);
},
function(callback){
var message = 'two';
setTimeout(function(){
Ti.API.info(message);
callback(null, message);
}, 500);
},
], function(err, results){
// results の中身は ['one', 'two']
Ti.API.warn(results);
});
var win = Ti.UI.createWindow({
title: 'Tab 1',
backgroundColor: '#fff'
});
var tab_group = Ti.UI.createTabGroup();
var tab = Titanium.UI.createTab({
title: 'Window',
window: win
});
tab_group.addTab(tab);
tab_group.open();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment