Skip to content

Commit

Permalink
boat: add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed May 30, 2016
1 parent 17fdd7a commit f29d5e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,47 @@
[![npm downloads](https://img.shields.io/npm/dm/sails-boat.svg?style=flat-square)](https://www.npmjs.com/package/sails-boat)
[![npm license](https://img.shields.io/npm/l/sails-boat.svg?style=flat-square)](http://magicdawn.mit-license.org)

## Features

- [x] `async/await` / `generator-function` support in `boat.action`
- [x] `boat.defaultErrorHandler` as error handle

## Install
```
npm i sails-boat --save
```

## API
```js
const boat = require('sails-boat');
```
const sailsBoat = require('sails-boat');


### `boat.action`

`boat.action(fn, errorHandler)`

- fn: async function / generator-function / normal function, with `(req, res)` para
- errorHandler: defaults to `boat.defaultErrorHandler`, with `(req, res, err)` para

```js
const boat = require('sails-boat');
const sleep = require('promise.delay');

// api/controller/HelloController.js
module.exports = {
world: boat.action(function*(req, res){
yield sleep(100); // sleep 100ms
var results = yield SomeModel.find();
res.send(results);
}),

foo: boat.action(async function(req, res){
await sleep(100);
var results = await SomeModel.find();
res.send(results);
})
}
```

## Changelog
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@
"mocha": "^2.4.5",
"sails": "^0.12.3",
"should": "^8.3.1"
}
},
"files": [
"index.js",
"package.json",
"README.md",
"LICENSE"
]
}

0 comments on commit f29d5e2

Please sign in to comment.