tra / spawnling

spawn gem for Rails to easily fork or thread long-running code blocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I need small usability fix, hope you like it :)

html opened this issue · comments

Hi, thank you for the great plugin :). I'm working now on server side part of flash game. I needed some logic to repeat every few seconds. I decided to move this logick into initializer (to run only once, forever with delay). Here is what i got

require 'spawn'

class Spawner
  extend Spawn
end

Spawner::spawn do
  while true
    # Doing my stuff
    sleep(5)
   end
end

And here is what i would like to have

Spawner::spawn do
  while true
    # Doing my stuff
    sleep(5)
  end
end

The problem is that Spawn is a module and we cannot use it in "Spawn::spawn do ..." way, so i needed to extend some class with this module and using that class. I think moving something like

class Spawner
  extend Spawn
end

into plugin code would be great idea.

Also plugin will need some documentation update. When i searched similar functionality (1 process for application that runs forever with delay) i have not found exactly what i need. This feature is not described anywhere.

Sounds like you need to create a script that runs indefinitely and sleeps every few seconds... just like you have written it but without spawn. I'm not sure that spawn is necessary for what you're doing.

It is not necessary but could be useful in some cases (due to hosting restrictions for example). You decide.