BackendStack21 / 0http

Zero friction HTTP requests router. The need for speed!
https://0http.21no.de
MIT License
158 stars 11 forks source link

feat(low-server): add response writable #14

Closed jesusvilla closed 4 years ago

jesusvilla commented 4 years ago

For the issue: #13

jkyberneees commented 4 years ago

Hi @jesusvilla thanks for your followup with a PR here.

I have look and applied your implementation to the existing code base and your feature is now released at: https://github.com/jkyberneees/0http/releases/tag/v2.4.0

Unfortunately, I decided to not merge this PR because I have also found an issue while processing the request headers that causes creating a generic function such as forEachObj unnecessary.

I also have to say, basic for loops vs foreach result more performant on my side, also confirmed by independent tests on the internet.

Anyway, thank you very much for pushing this feature. I properly mentioned you on the release notes.

jesusvilla commented 4 years ago

Hi @jkyberneees thanks for taking it into consideration. For forEachObj https://jsperf.com/foreach-object/1 image

function forObject (obj, cb) {
  const keys = Object.keys(obj)
  for (let i = 0, length = keys.length; i < length; i++) {
    cb(obj[keys[i]], keys[i])
  }
}

You're right, a classic for is faster for objects, but a forEach is faster for arrays, anyway it's always nice to have it in a function that does the work, you should also consider it, because when you want to iterate objects you're going to always have to copy and paste the same code.