Skip to content
This repository was archived by the owner on Jul 15, 2021. It is now read-only.

Commit 62f353b

Browse files
committed
Parser was blocking when called as async func.
Fixed so that the parser is called in a non-blocking way when called with a second argument callback function.
1 parent 7693455 commit 62f353b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ import {isFunc} from './lib/parser-util';
66
import Tracer from './lib/tracer';
77

88
export default function sqliteParser(source, callback) {
9-
let res, err;
109
const t = Tracer();
1110
const isAsync = isFunc(callback);
11+
const opts = { 'tracer': t };
12+
// Async
13+
if (isAsync) {
14+
setTimeout(function () {
15+
try {
16+
callback(null, parser(source, opts));
17+
} catch (e) {
18+
callback(t.smartError(e));
19+
}
20+
}, 0);
21+
return;
22+
}
23+
// Sync
1224
try {
13-
res = parser(source, { 'tracer': t });
25+
return parser(source, opts);
1426
} catch (e) {
15-
err = t.smartError(e);
16-
}
17-
if (isAsync) {
18-
callback(err, res);
19-
} else {
20-
if (err) { throw err; }
21-
return res;
27+
throw t.smartError(e);
2228
}
2329
};
2430

0 commit comments

Comments
 (0)