Skip to content

Instantly share code, notes, and snippets.

@stoodfarback
Last active May 1, 2016 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoodfarback/826a49410f8f1add96014f72452285e3 to your computer and use it in GitHub Desktop.
Save stoodfarback/826a49410f8f1add96014f72452285e3 to your computer and use it in GitHub Desktop.
def msg(str)
@state ||= Concurrent::Map.new
if @last_msg && (Time.now - @last_msg) < 1
@state[:str] = str
task = @state[:scheduled_task]
if !task || !task.pending?
@state[:scheduled_task] = Concurrent::ScheduledTask.execute(1) do
update_db_with_msg(@state[:str])
end
end
else
update_db_with_msg(str)
end
@last_msg = Time.now
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment