yortus / asyncawait

Callback heaven for Node.js with async/await
MIT License
1.91k stars 77 forks source link

Use with ES6 classes #2 #52

Closed cosmicscr closed 7 years ago

cosmicscr commented 7 years ago

Github will not let me leave more comments in the original issue:
https://github.com/yortus/asyncawait/issues/48

... so I'm creating a new issue here. The error is "You can't perform that action at this time" when I try to leave a comment. Here is the comment:

To use this asyncawait library with ES6 classes, why not just add the async function to the class prototype? That seems easy and direct:

const async = require('asyncawait/async')
const await = require('asyncawait/await')

class MyClass {
    firstMethod() {
        console.log('firstMethod')
    }
}

MyClass.prototype.secondMethod = async(function () {console.log(await('secondMethod'))})

const myClassInstance = new MyClass()

console.log(myClassInstance.firstMethod())

myClassInstance.secondMethod().then(function (data) { console.log(data)})```

Output is:

firstMethod secondMethod



Please let me know if I am missing something here.
cosmicscr commented 7 years ago

Figured out the github issue... there is something wrong with my chrome plugins that is blocking me. I updated original issue instead of this one.