something like this
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
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