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
eval(Mr.Async.recode(function(){ | |
var i = $await(delay()); // 等待 | |
console.log(i); | |
})); |
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
// 一个实现了Mr.Deferred的通用异步方法 | |
// 等待一秒钟,计算一个0到1的随机数 | |
function asyncRandom(callback){ | |
var de = Mr.Deferred(); | |
setTimeout(function(){ | |
var random = Math.random(); | |
if(typeof callback == 'function') | |
callback(random); | |
de.resolve(random); | |
}, 1000); |
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
// 算法本身 | |
for(var i = 0 ; i < arr.length - 1 ; i++){ | |
for(var ii = i + 1; ii < arr.length ; ii++){ | |
if(arr[i] > arr[ii]) | |
normalSwap(arr, i, ii); | |
} | |
} | |
// 利用了Mr.Async.Interpreter的方式 | |
eval(Mr.Async.recode(function(){ |
NewerOlder