teambition / RRuleSwift

Swift rrule library for working with recurrence rules of calendar dates.
MIT License
97 stars 74 forks source link

static JSContext issue with multiple threads #20

Closed BlixLT closed 3 years ago

BlixLT commented 3 years ago

It seems that static JSContext (Iterator.rruleContext) is causing problems when there are quite a few calculations in differnet threads. It happens, when in some rare cases two context?.evaluateScript("var rule = new RRule({ \(ruleJSONString) })") is being called one after another and only then two dates calculations

        guard let allOccurrences = context?.evaluateScript("rule.all()").toArray() as? [Date] else {
            return []
        }

one after another. In such case the second new RRule({ \(ruleJSONString) }) overwrites first RRule's properties in static JSContext and first calculation uses wrong parameters. One way to avoid this issue would be not using static JSContext, but recreate it for each calculation. So, thats my suggestion. Not ideal, but at least it solves this dates calculation problem for me. Maybe you can suggest a better solution.

BlixLT commented 3 years ago

ok, this solution is not very efficient - recreating JSContext each time. So I will make another pull request with IMO better solution.