Skip to content

Instantly share code, notes, and snippets.

View winsonwq's full-sized avatar
🎯
Focusing

Wang Qiu winsonwq

🎯
Focusing
  • 可好玩乐
  • Chengdu China
View GitHub Profile
@winsonwq
winsonwq / simpleAwait.js
Created January 3, 2012 08:26
How to use Mr.Async.recode method
eval(Mr.Async.recode(function(){
var i = $await(delay()); // 等待
console.log(i);
}));
@winsonwq
winsonwq / MrDeferredInAwait.js
Created January 3, 2012 08:24
How to use $await in Mr.Async
// 一个实现了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);
@winsonwq
winsonwq / bubbleSortOfMrAsyncInterpreter.js
Created January 3, 2012 08:21
BubbleSort of Mr.Async.Interpreter
// 算法本身
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(){