pointfreeco · GitHub

Description

I am not able to reproduce this, but observed in production that the dates retrieved using @Dependency(\.date.now) are incorrect in many cases. Some times they are from future and sometimes they are from past.

After going through the documentation, i've noticed that it's stated here that we should use withEscapedDependencies to reflect correct values in case of passing over dependencies to escaping closures. Would this apply for the dependencies provided by default like Date as well ?

Would using withEscapedDependencies solve the issue with incorrect dates ?

Here is a sample code to demonstrate how I am using the value of date from @Dependency(\.date.now) in an escaping closure, if that would be helpful to understand more about the issue.

@Dependency(\.date.now) private var now
private var startTime: Date?
private let scheduler: AnySchedulerOf<DispatchQueue>
.....
scheduler.schedule { [weak self, now] in
            self?.startTime = now
 }

In the above codebase I am seeing startTime is getting assigned with date either from future or past.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Correct date value should be available inside the closure.

Actual behavior

Incorrect date values are available within the closure.

Steps to reproduce

I am not able to reproduce this, may be this is happening at a high level of concurrency.

Dependencies version information

1.6.1

Destination operating system

Across iOS versions

Xcode version information

No response

Swift Compiler version information

Read the original on github.com ↗