module Non::Blocking

Overview

This is a fork of top level spawn, but when same_thread is false, it makes sure that the fiber spawns in any worker thread BUT the current one.

If only the current one is available, it falls back to leaving it up to Crystal::Scheduler to decide.

https://crystal-lang.org/api/1.5.0/toplevel.html#spawn%28%2A%2Cname%3AString%3F%3Dnil%2Csame_thread%3Dfalse%2C%26block%29-class-method

https://github.com/crystal-lang/crystal/blob/932f193ae/src/concurrent.cr#L60-L67

Extended Modules

Defined in:

non-blocking-spawn.cr

Instance Method Summary

Instance Method Detail

def spawn(*, name : String | Nil = nil, same_thread = false, &block) : Fiber #

Spawns a fiber in either the same worker thread or any BUT the current one.

Example:

Non::Blocking.spawn do
  loop do
    puts "hello world"
  end
end

[View source]
def threads : Array(Thread) #

Returns the amount of available worker threads excluding the current one.

Example:

puts Non::Blocking.threads.size

[View source]