-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made time_class thread safe #214
base: master
Are you sure you want to change the base?
Conversation
Seems good. 👍 |
Probably |
I don't think this is necessary. I'd like to add the ability to use debug/time_class configuration values per Parser instance. That would solve the problem of hitting race conditions. Then Chronic.parse('next tuesday at 3pm', time_class: Time.zone) I'm not too worried about the debug flag, though. If someone has enabled debugging they should expect to see it everywhere. |
Well I think thread safety is needed. To allow configuration, could create it could be like this class << self
def global_time_class
@@global_time_class || ::Time
end
def global_time_class=(time)
@@global_time_class = time
end
def time_class
Thread.current[:__Chronic_time_class] || global_time_class
end
def time_class=(time)
Thread.current[:__Chronic_time_class] = time
end
end then As for debug could do same, it's minor change and maybe for some cases it might be useful to debug only single thread. |
Again I don't think this is necessary. If we are going to go the route of making stuff thread stuff like this, then it should be kept simple: class Chronic
def self.time_class
Thread.current[:chronic_time_class] || ::Time
end
def self.time_class=(klass)
Thread.current[:chronic_time_class] = klass
end
end There's no need for the prefixed underscores, or the capitalized class name, it's adding unnecessary complexity to what's essentially a simple subject. However, I do still believe that we should allow setting the time class per |
I'm not saying we shouldn't, it's a must have. That global class variable would be just extra. But maybe not really needed then, I just like very customizable software so to fit everyone needs 😆 |
++ thread safety |
+1. Also it may be worth looking at how Timecop handles this and whether Timecop is threadsafe. I like the Timecop API since it lets you run arbitrary code within the block. If we were to copy it for Chronic: Chronic.time_class(Time.zone) do
Chronic.parse('next tuesday at 3pm')
end |
+1 thread safety |
Whatever came about this? Is |
This should fix #189 and might close #182