Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

started() and stopped() #7

Closed
AndreMaz opened this issue Dec 7, 2018 · 3 comments
Closed

started() and stopped() #7

AndreMaz opened this issue Dec 7, 2018 · 3 comments

Comments

@AndreMaz
Copy link
Member

AndreMaz commented Dec 7, 2018

I think I found a solution to the started() and stopped() methods:

// started() {
// },
/**
* Service stopped lifecycle event handler
*/
// stopped() {
// },

That currently shows the following problem:
Type '() => void' is not assignable to type '() => Bluebird<void>'. Type 'void' is not assignable to type 'Bluebird<void>'.

The problem is in Moleculer's index.d.ts that requires returning a Bluebird promise

started?: () => Bluebird<void>;
stopped?: () => Bluebird<void>;

Because of this the only way to declare the started and stopped is

started() {
   return this.Promise.resolve() // this.Promise is a reference to Bluebird promise
}

However, it should be possible to use native promises and async/await. To make it work
index.d.ts must be updated as follows:

started?: () => PromiseLike<void>;
stopped?: () => PromiseLike<void>;

With PromiseLike the compiler will accept anything that looks like a promise.

@faeron @icebob I think this change won't break anything but I'm not sure because I'm a complete newbie in Typescript

@faeron
Copy link
Contributor

faeron commented Dec 7, 2018

Nice find ! 👏👏 I didn't find that solution when porting the template, thats why they are commented out :D
I also think that a change to the definition would not break anything.

@icebob
Copy link
Member

icebob commented Dec 7, 2018

I'm not a typescript guy, so I can't consider it, but please make a PR in moleculer repo and we will ask somebody to review it.

@AndreMaz
Copy link
Member Author

AndreMaz commented Jan 9, 2019

Solved in #422

@AndreMaz AndreMaz closed this as completed Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants