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

setObject Thread Problem #181

Closed
mcfans opened this issue Apr 19, 2018 · 3 comments
Closed

setObject Thread Problem #181

mcfans opened this issue Apr 19, 2018 · 3 comments

Comments

@mcfans
Copy link

mcfans commented Apr 19, 2018

The code below will lead to dead lock,because in the setObjectmethod it will try to encode this class in a sync queue,but in the encodemethod,the user try to set something in that sync queue.

class DeadLock: Codable{
    ///
    func encode(to encoder: Encoder) throws {
        try storage.setObject("", forKey: "Something")
    }
}
try? storage.setObject(DeadLock(), forKey: "Some other")
@vadymmarkov
Copy link
Contributor

Hey @mcfans! Yes, it will happen in your example, but why would you need to do that?

@mcfans
Copy link
Author

mcfans commented Apr 19, 2018 via email

@vadymmarkov
Copy link
Contributor

In this case I would just do it a bit differently: save Codable object at first and then save the generated key (not in encode function). The current implementation of Cache is not suitable for those kind of nested operations. This example looks more like an edge case to me. But thanks for you feedback @mcfans 😉

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

No branches or pull requests

2 participants