croservices / cro-core

The heart of the Cro library for building distributed systems in Raku, including pipeline composition and TCP support.
https://cro.services/
Artistic License 2.0
27 stars 9 forks source link

Using dynamic port numbers #37

Open jmaslak opened 1 year ago

jmaslak commented 1 year ago

It would be amazing if there was a way you could get the port number Cro listens at when you pass it a "0" for the port number. This would let Cro bind to a free port, which could be very useful in test harnesses, as hardcoding a port in the test harness is not guaranteed to be free from collisions. However, today there is no way that I know of to determine the port number it binds to if using a dynamic port, at least not in a portable way.

jmaslak commented 1 year ago

FWIW, I'm working around this by swapping out the listener in the service object with one that lets me get the port number. But using Cro this way feels...really wrong. :)

See example: https://gist.github.com/jmaslak/ba3cbfe1abd13b76ac906cfaeb0f62e9