Skip to content

Commit

Permalink
feat: suppory async
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot committed Mar 27, 2018
1 parent 583209b commit 5624319
Show file tree
Hide file tree
Showing 19 changed files with 517 additions and 531 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- '6'
- '8'
install:
- npm i npminstall && npminstall
env:
Expand Down
23 changes: 13 additions & 10 deletions example/producer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
'use strict';

const co = require('co');
const logger = require('./logger');
const config = require('./config');
const httpclient = require('urllib');
const Producer = require('../').Producer;
const Message = require('../').Message;

const producer = new Producer(Object.assign({ httpclient, logger }, config));
co(function*() {
yield producer.ready();
const msg = new Message(config.topic, // topic
'TagA', // tag
'Hello ONS !!! ' // body
);
(async () => {
try {
await producer.ready();
const msg = new Message(config.topic, // topic
'TagA', // tag
'Hello ONS !!! ' // body
);

const sendResult = yield producer.send(msg);
console.log(sendResult);
}).catch(err => console.error(err));
const sendResult = await producer.send(msg);
console.log(sendResult);
} catch (err) {
console.error(err)
}
})();
8 changes: 4 additions & 4 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class Channel extends Base {
* @param {Number} timeout - response timeout
* @return {Object} response
*/
* invoke(command, timeout) {
async invoke(command, timeout) {
this.beforeRequest(command);
return yield this.sendThunk({
return await this.sendThunk({
id: command.opaque,
data: command.encode(),
timeout,
Expand All @@ -112,9 +112,9 @@ class Channel extends Base {
* @param {RemotingCommand} command - remoting command
* @return {void}
*/
* invokeOneway(command) {
async invokeOneway(command) {
this.beforeRequest(command);
yield this.sendThunk({
await this.sendThunk({
id: command.opaque,
data: command.encode(),
oneway: true,
Expand Down
Loading

0 comments on commit 5624319

Please sign in to comment.