Skip to content

Commit

Permalink
remove process.nextTick, callbacks are sync by default (see wit-ai#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy Blandin committed Apr 28, 2016
1 parent d4e748e commit 104bd1a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v3.3.0

- callbacks are not called asynchronously by default, choice is left to the developer (use process.nextTick in your callback to emulate the previous behavior)

## v3.2.2

- fixing context not updated in interactive mode
Expand Down
20 changes: 5 additions & 15 deletions lib/wit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const makeWitResponseHandler = (endpoint, l, cb) => {
const error = err => {
l.error('[' + endpoint + '] Error: ' + err);
if (cb) {
process.nextTick(() => {
cb(err);
});
cb(err);
}
};

Expand All @@ -41,9 +39,7 @@ const makeWitResponseHandler = (endpoint, l, cb) => {

l.debug('[' + endpoint + '] Response: ' + JSON.stringify(json));
if (cb) {
process.nextTick(() => {
cb(null, json);
});
cb(null, json);
}
}
};
Expand Down Expand Up @@ -88,9 +84,7 @@ const makeCallbackTimeout = (ms) => {
const cbIfActionMissing = (actions, action, cb) => {
if (!actions.hasOwnProperty(action)) {
if (cb) {
process.nextTick(() => {
cb('No \'' + action + '\' action found.');
});
cb('No \'' + action + '\' action found.');
}
return true;
}
Expand Down Expand Up @@ -226,9 +220,7 @@ const Wit = function(token, actions, logger) {
error = error || !json.type && 'Couldn\'t find type in Wit response';
if (error) {
if (cb) {
process.nextTick(() => {
cb(error);
});
cb(error);
}
return;
}
Expand All @@ -237,9 +229,7 @@ const Wit = function(token, actions, logger) {
if (json.type === 'stop') {
// End of turn
if (cb) {
process.nextTick(() => {
cb(null, context);
});
cb(null, context);
}
return;
} else if (json.type === 'msg') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-wit",
"version": "3.2.2",
"version": "3.3.0",
"description": "Wit.ai Node.js SDK",
"keywords": [
"wit",
Expand Down

0 comments on commit 104bd1a

Please sign in to comment.