Is the API synchronous?
tommiv opened this issue · comments
Konstantin Ilchenko commented
I want to use this lib (thanks for it) on tcp socket – as standalone parser. I need to emulate some legacy protocol that can send to tcp socket http data as well as raw commands. So I need to know, is this guaranteed that all callbacks are called when I call .finish()
/.close()
? I used this code to check things out:
const parser = new HTTPParser(HTTPParser.REQUEST);
parser[0] = () => console.log('onHeaders');
parser[1] = headersRaw => console.log('onHeadersComplete', headersRaw);
parser[2] = body => console.log('onBody', body);
parser[3] = () => console.log('onMessageComplete');
parser.execute(this.buffer);
parser.finish();
parser.close();
console.log('complete');
in my experiments complete
message always showed up after all callbacks, but it would be great to be sure about it and not wrap the code in promise.
Jan Schär commented
Yes, you can look at the code yourself; callbacks are only called inside parser.execute(buffer)
and parser.finish()
.
Konstantin Ilchenko commented
Great, thank you for blazing fast response!