Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a short syntax in javascript for a call chain containing synchronous and asynchronous methods of the same class?

I know of 2 ways that are not very convenient and look inelegant:

  1. Via then:

    (new TestClass).syncMethod().asyncMethod().then(self => self.anotherSyncMethod())

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  2. Via await:

    (await (new TestClass).syncMethod().asyncMethod()).anotherSyncMethod()

I expect it to be something like this (pseudocode):
(new TestClass).syncMethod().asyncMethod()->anotherSyncMethod()
where -> is the transition from an async method to a synchronous one.

Is there something like this in JS, and if not, is there any plans for it in the future?

>Solution :

There is not.

However, the proposed pipeline operator might enable this in the future. You can find some bikeshedding in disussions there, like in issues #53, #86, #145, #189.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading