lvivski / start

Sinatra inspired web development framework for Dart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use async operations with Start?

sma opened this issue · comments

Could you please provide an example how to use async operations with Start?

I tried this, but it didn't work:

app.get('/:name', (req, res) {
  new File(req.param('name')).readAsString().then((content) {
    res.render('view', {'content': content});
  });
});

It seems, the response stream is closed before the Future's function is called.

The problem is deeper, so I'll rewrite the routing management. The case is that default router (send file) catches and sends 404 :)

Here's some basic fix for async handlers, see example. I'll refactor it, but it seems to work