This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Inline Web Worker</title> | |
</head> | |
<body> | |
</body> | |
<script type="javascript/worker" id="my-worker"> |
This file contains 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 coPromise (genFun, ctx) { | |
return new Promise(function (resolve, reject) { | |
co(genFun).call(ctx, function (err, data) { | |
if (err) { | |
return reject(err); | |
} | |
resolve(data); | |
}); | |
}); |
This file contains 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
// require Proxy API normalization polyfill because current V8's implementation doesn't support standardized API | |
const Reflect = require('harmony-reflect'); | |
function createProxy (action) { | |
// create the callable proxy | |
function _createCallableProxy (name) { | |
const methodNames = [ name ]; | |
return new Proxy(function () {}, { |
This file contains 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 negArray (arr) { | |
return Proxy.create({ | |
get: function (rcvr, index) { | |
index = +index; | |
return arr[index < 0? arr.length + index : index]; | |
}, | |
set: function (rcvr, index, value) { | |
index = +index; | |
return arr[index < 0? arr.length + index : index] = value; |
This file contains 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
'use strict'; | |
function async (generator, callback) { | |
if (generator.constructor.name !== 'GeneratorFunction') { | |
throw new Error('Function async accept only generator function.'); | |
} | |
function handleResult (result) { | |
let resultValue = result.value; |
This file contains 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
Q.async(function* () { | |
try { | |
var value1 = yield step1(); | |
var value2 = yield step2(value1); | |
var value3 = yield step3(value2); | |
var value4 = yield step4(value3); | |
} catch (e) { | |
// Handle any error from step1 through step4 | |
} | |
}); |