Skip to content

Instantly share code, notes, and snippets.

@The-Quill
Last active June 30, 2016 02:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save The-Quill/c6ea3b6e8236337453482a0b89a19bb1 to your computer and use it in GitHub Desktop.
something like this
import request from 'request-promise'
class Task {
constructor(func){
this.func = func
this.deferredTask = null;
}
set subTask(task){
this.deferredTask = task;
}
async materialise(...options){
var result;
if (this.func instanceof Task){
result = await this.func.materialise(...result)
} else {
result = await this.func(...options)
}
if (this.deferredTask instanceof Task){
return await this.deferredTask.materialise(...result)
}
return await this.deferredTask(...result)
}
}
function a(...options){
console.log(options)
return request(...options)
}
async function b(results){
return await results
}
var aTask = new Task(a({
gzip: true,
url: 'http://api.stackexchange.com/2.2/sites'
}));
aTask.subTask = b;
var bTask = new Task(aTask);
bTask.subTask = b;
(async function(){
let r = await bTask.materialise()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment