Skip to content

Instantly share code, notes, and snippets.

@brian-gates
Created February 21, 2014 19:26
Show Gist options
  • Save brian-gates/9141529 to your computer and use it in GitHub Desktop.
Save brian-gates/9141529 to your computer and use it in GitHub Desktop.
Oboe.js in a worker thread
var worker = new Worker("/javascripts/oboe_worker.js");
worker.onmessage = function(event) {
var message = JSON.parse(event.data);
if(message.path == '!*.user') {
console.log(message.data);
}
}
worker.postMessage(JSON.stringify({
url : 'http://localhost:3000/v1/users',
method : 'GET',
paths : ['!*.user']
}))
var window = window || {}; // this is required since there isn't a window object in worker context
... rest of the file here ...
importScripts('oboe-browser.js');
var oboe = window.oboe;
function sendData(data) {
postMessage(JSON.stringify(data));
}
onmessage = function(event) {
var message = JSON.parse(event.data);
var req = oboe({
url : message.url,
method : message.method,
headers : message.headers,
})
.fail(function fail(error) {
throw error;
});
message.paths.forEach(function(path){
req.node(path, function(data) {
sendData({ path: path, data: data })
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment