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

async/await support #130

Closed
mgenev opened this issue May 31, 2015 · 13 comments
Closed

async/await support #130

mgenev opened this issue May 31, 2015 · 13 comments

Comments

@mgenev
Copy link

mgenev commented May 31, 2015

I enabled async/await per this conversation koajs/koa#415
Everything's working, except when I get this module involved and switch my functions from generator to async, I start getting undefined is not a function coming out of this module, I suspect it's not async/await compliant?

@alexmingoia
Copy link
Collaborator

Works fine for me using babel. What are you using to transform?

@mgenev
Copy link
Author

mgenev commented Jun 1, 2015

Babel as well, do you have an example where I can see it working? Mine is public
Works for all the other middleware, but if I switch these routes to async/await from */yield It breaks.
https://github.com/mgenev/nautilus/blob/async/server/controllers/post.js

Here is the babel setup:
https://github.com/mgenev/nautilus/blob/async/server/run.js

I also tried using 'asyncToGenerator' instead of bluebird, different error but also breaks...

@mgenev
Copy link
Author

mgenev commented Jun 4, 2015

Just tried again, this works as intended:

import koa from 'koa';
var router = require('koa-router')();
let app = koa();

app.experimental = true;

router.get('/meh',  function* (next) {
  this.body = 'MEH MEH MEH';
});

app.use(router.routes()).use(router.allowedMethods());
app.server = app.listen(3000);

this:

import koa from 'koa';
var router = require('koa-router')();
let app = koa();

app.experimental = true;

router.get('/meh',  async function (next) {
  this.body = 'MEH MEH MEH';
});

app.use(router.routes()).use(router.allowedMethods());
app.server = app.listen(3000);

gives me error:

  TypeError: next[(intermediate value)] is not a function
      at Object.dispatch (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa-router/lib/router.js:331:14)
      at GeneratorFunctionPrototype.next (native)
      at Object.respond (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/lib/application.js:180:10)
      at GeneratorFunctionPrototype.next (native)
      at onFulfilled (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/co/index.js:64:19)
      at /Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/co/index.js:53:5
      at Object.co (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/co/index.js:49:10)
      at Wrap.<anonymous> (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/composition/index.js:48:19)
      at Wrap.Object.defineProperty.get (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/composition/node_modules/memorizer/index.js:5:38)
      at Wrap.catch (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/node_modules/composition/index.js:98:14)
      at Server.<anonymous> (/Users/martin.genev/Projects/temp/asynckoa/node_modules/koa/lib/application.js:128:23)
      at emitTwo (events.js:87:13)
      at Server.emit (events.js:169:7)
      at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:471:12)
      at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
      at Socket.socketOnData (_http_server.js:322:22)

my babel settings:

require('babel/register')({
  optional: ['asyncToGenerator']
});

versions:

    "koa": "^0.21.0",
    "koa-router": "^5.1.1"

What am I doing wrong? How were you able to get it to work?

@bernhardw
Copy link

It would be great to have (experimental) support for async functions through promises as well.

@alexmingoia alexmingoia changed the title seems to break with async/await async/await support Jun 8, 2015
@geddski
Copy link

geddski commented Jul 22, 2015

I'd like this as well 👍

@juhaelee
Copy link

juhaelee commented Aug 4, 2015

👍

@mvila
Copy link

mvila commented Aug 10, 2015

I am switching all my projects from ES6 generators to ES7 async functions... So, a big 👍 for me too!

@alexmingoia alexmingoia added this to the 6.0.0 milestone Aug 19, 2015
@dvlsg
Copy link

dvlsg commented Aug 21, 2015

👍 This functionality would get me to move all of my projects to koa as soon as it is available. Would be a fantastic feature.

@ujenjt
Copy link

ujenjt commented Aug 21, 2015

👍 really need this feature

@niieani
Copy link

niieani commented Aug 25, 2015

👍 Would be awesome.

@xmlking
Copy link

xmlking commented Sep 19, 2015

👍

ruiquelhas pushed a commit to seegno-forks/koa-router that referenced this issue Oct 16, 2015
@menems
Copy link

menems commented Oct 16, 2015

Hi everyone,

So as I understand this commit is for the experimetal option on koa master branch? not for the new signature proposal with ctx on params?

@alexmingoia
Copy link
Collaborator

The experimental option.

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

No branches or pull requests