2

I am trying to do use the http-kit client library in clojure to do synchronous posts returning promises. Is there any way to limit the number of threads doing the actual post?

All the examples I could find of using the inbuilt thread pool use the lower level primitive function called request but they were all for http/get.

Thanks

ducky
  • 1,113
  • 1
  • 11
  • 23
  • 1
    I realised that I can use the [claypoole](https://github.com/TheClimateCorporation/claypoole) library to get want I wanted. – ducky Feb 27 '14 at 17:50

1 Answers1

1

I'm assuming you've seen http://http-kit.org/client.html#sync

My question is do you want to do a synchronous POST, or limit the number of threads? You can do a sync POST with 100 threads, it just so happens you're main thread will wait for the request to return.

Maybe more importantly, why do you want to limit the number of threads?

Also, see https://github.com/http-kit/http-kit/blob/master/src/org/httpkit/client.clj, specifically request. You can handle it a map of arguments, like {:url "http://yoursite.com" :worker-pool my-thread-pool-executor}

my-thread-pool-executor has to extend ExecutorService.

Specifically, you need to overload submit which is what the RespListener uses in http-kit. You could make submit synchronous with your own ExecutorService implementation so it runs on the same thread.

nathas
  • 949
  • 1
  • 9
  • 15