Running server with HTTP.jl in async mode?

Hi,
I have created a http web service, the concept is taken from the presentation of Quinnj’s MusicAlbum project. 1 thing I am not sure about. If I want to initiate the server with @async mode from the terminal it initiating and closing the server immediately. Here is the file in the repo . Running julia --t 2 serve.jl it initiate the server and close it immediately after execution. but if do not use @async it keeps the server running untill I do not kill it. But Quinnj some how was able to to keep the server running in his demo using his Client . But what if my client is in Go or Javascript. Then I just want my server up and running with @async mode and do not care about compilation.

If your Julia process is not going to do anything other than running the server there is no point in spawning a new task (@async) for running the HTTP server.

If the process is going to do other things after launching the server you can prevent Julia from exiting by waiting for the server task:

server_task = @async run_server()

# Do other stuff here...

# Keep Julia alive for as long as the server is running
wait(server_task)
4 Likes

The implementation language of the client doesn’t matter, only the actual HTTP interaction. Different client libraries may have different defaults that could affect the interaction, for example timeouts.

1 Like

It seems like I miss understood the client part of the Project from Quinnj. Actually he runs the server in the docker. But In his client side probably because he run stuff concurrently so he started the server with @async.

If you are saying that the client and the server are in the same process, then yes, they need to run async so both get time to run. Otherwise, one or the other would block waiting for I/O and the other couldn’t respond. To simulate an environment closer to production, client and server ought to be at least separate processes, or better, running on separate computers or even in separate networks.

1 Like

Good Point. Thanks for the clarification.