Skip to content
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

Added override for specifying the global actor of mocked async functions #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stuaustin
Copy link

Issue

#249 Async functions are unsafe in generated mocks, and can crash if used from multiple threads simultaneously

Description

This change lets you specify the global actor that is used for your generated mock's async functions. This can be used to solve the problem described in #249 as when used there is no longer the chance for the async functions to be executed multiple times simultaneously.
I have allowed the user to specify the global actor so that they can choose to use a custom GlobalActor instead of assuming they always want to use the MainActor.

@sidepelican
Copy link
Collaborator

Thank you for your contribution.

While this feature is opt-in, I don't believe using a GlobalActor is the fundamental solution. Introducing locks would be the correct approach to address exclusive access issues.

However, mockolo currently lacks a suitable lock implementation. NSLock depends on Foundation, and swift-atomics might not always be available. I’m looking forward to the standard library introducing a Mutex.
https://github.com/apple/swift-evolution/blob/main/proposals/0433-mutex.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants