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

Implement async/await interface #106

Closed
4 tasks done
tshemsedinov opened this issue Jan 1, 2020 · 4 comments
Closed
4 tasks done

Implement async/await interface #106

tshemsedinov opened this issue Jan 1, 2020 · 4 comments

Comments

@tshemsedinov
Copy link
Member

tshemsedinov commented Jan 1, 2020

Implement async/await interface in addition to events and callbacks.

  • Constructor const logger = await new Logger();
  • Open await logger.open();
  • Close await logger.close();
  • Rotate await logger.rotate();
@Bob-chemist
Copy link
Contributor

Can you, please, give a hint on implementation of async/await in constructor?

@Bob-chemist
Copy link
Contributor

Can you, please, give a hint on implementation of async/await in constructor?

I've found it in your "Async programming" course.
But I still can't understand - does "in addition" mean that we will be able to call constructor and other methods both inside async functions and in synchronous code?
E.g.?:

(async () => {
    const logger2 = await new Logger();
})();

const logger3 = new Logger();

@tshemsedinov
Copy link
Member Author

See this for example: https://github.com/metarhia/config/blob/master/config.js#L11
You can call it const config = await new Config(path);

@tshemsedinov
Copy link
Member Author

If we return promise from constructor we definitely need to wrap await new into async function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants