rock-req icon indicating copy to clipboard operation
rock-req copied to clipboard

Async support?

Open cb-rnag opened this issue 1 year ago • 2 comments

Is there any future plans for async support, e.g. with await?

I like libraries like node-fetch and axios, as one of the things they ship "out of the box" is ability to use promise and support async-await pattern in node/express.

My question, has the benchmarks for this library - which are pretty impressive btw - been tested in an async environment? Also, how would one go about "promisifying" a library such as rock-req, if I may ask? That is, would it be possible to wrap such a library in an async block to use with await?

cb-rnag avatar Dec 22 '23 19:12 cb-rnag

Hello,

Yes, we could support await/async.

Have you tried to use the native NodeJS function to promisify rock.req with util.promisify?

const rockGet = util.promisify(rock.get);

has the benchmarks for this library - which are pretty impressive btw - been tested in an async environment?

Not yet. In general, it is slower.

dgrelaud avatar Jan 08 '24 16:01 dgrelaud

Nice, I haven't played around with (or even heard of) util.promisify but that looks promising to me (no pun intended).

Will try with that approach and see if I can get it to work. However, still do agree that it would be great if rock-req support this OOTB, as I feel it could be a worthwhile addition. I would be happy to implement as well, but I'm not sure on the process for going about that, e.g. how can await/async be added natively.

cb-rnag avatar Jan 19 '24 00:01 cb-rnag