I think the webview#run is the culprit. The server.listen allows other fibers to run in the thread while the connections are waited using IO events. But webview#run does not yield the fiber execution.
If you want this you need to go to multi-thread or at least as an alternative wraps the wv.run in a
Thread.new do
wv.run # probably wv.not_nil!.run
end
but note that manually creating Threads is not recommended / encouraged, and it might break depending on how the library internally works.
One could think that even if manually creating Threads will have problems (with doing IO, sleeping, Channel interaction etc), it would work if mt_preview was specified. Unfortunately however, the current scheduler will portion out newly spawned fibers over all the available threads, so if anything blocks without yielding to the scheduler it will block any fiber that is assigned to the same thread until it is done.
Go routines are spawned in multiple threads which are created by go runtime and that’s the default feature of Go. Crystal default is single-threaded, where it spawns fibers in same thread. So to achieve your goals you will have to either go with mt_preview mode for multi-threaded feature or the work-around of running two processes (as you mentioned in your comment).
Even with mt_preview on this may or may not work depending if the Fiber used to do the webview.run call end up in the same thread of webserver or not. The solution is to manually create a thread as bcardiff said or modify Crystal compiler to have an annotation on C function to tell it must call them in another thread like asterite said and Go does
Yes, but spawn default settings (argument same_thread is set to false as default value) is to run in separate thread. So for cited or in question use-case mt_preview with more than 1 thread is definitely going to work, as question was to run webserver and webview in same process.
same_thread: false doesn’t force the fiber to be scheduled on the same thread. But it does not exclude that. It’s up to the scheduler where it gets dispatched.