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

Any plans to support promises? #1588

Closed
StarpTech opened this issue Jan 1, 2018 · 4 comments
Closed

Any plans to support promises? #1588

StarpTech opened this issue Jan 1, 2018 · 4 comments

Comments

@StarpTech
Copy link

StarpTech commented Jan 1, 2018

Restify Version

Any

Feature Request

Use Case

Node.Js is increasingly developing but promises and async / await are the new standard to deal with asynchrony without a performance loss.

Are you willing and able to fix this?

Yes

Why do you want this?

In order to be compatible with the latest standard and be an example for "The future of Node.js REST development"

@retrohacker
Copy link
Member

retrohacker commented Feb 6, 2018

Hey @StarpTech,

Thank you for taking the time to open this issue.

Promises have some outstanding issues making them unsuitable for server side rest frameworks. While they are certainly the future, and will more than likely have some sort of support in this library in the future, there are currently no plans or timelines for treating them as first class constructs.

The most thorough conversation around including promises can be found here: #1304

There are several other cases where proposals have been made for including promises and we have concluded they aren't mature enough yet for our use case.

@StarpTech
Copy link
Author

Hi @retrohacker thank you, that's reasonable.

@leodutra
Copy link

leodutra commented Feb 6, 2018 via email

@joeytwiddle
Copy link

We wanted to use promises in our middleware and our route handlers, so we wrote two wrappers than can convert a promise-returning handler into a restify-compatible handler.

Example:

server.get(
  { path: '/users/_self', version: VERSION },
  middleware(authUserMiddleware),
  controller(getUserSelf)
);

async function authUserMiddleware(req) {
  const user = await authHelper.findUserFromToken(req.headers['x-auth-token']);
  if (!user) throw Error("No user found!");
});

function getUserSelf() {
  return Promise.resolve({
    name: 'Example User',
    color: 'green'
  });
}

You can get the two wrappers here:

https://gist.github.com/joeytwiddle/a3a038d88b9a689bddbfe7eab1b459af

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

4 participants