-
-
Save stoodfarback/826a49410f8f1add96014f72452285e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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