Created
December 2, 2012 14:07
-
-
Save astronaughts/4188863 to your computer and use it in GitHub Desktop.
【3日目】Titanium mobile でも使える非同期処理のためのライブラリ「async.js」
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
(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