-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Should async handover support Realm collections? #3863
Comments
If we are to support it, we ought to decide on the API. 1.
|
//cc @bigfish24 |
I am in favor of option 1 |
I just checked, and it turns out the function overloads discussed in 1 are ambiguous… 😞 If we want 1 still, we need to give the existential method a different name… Thoughts @bigfish24? For example, we could rename the latter to func async(handingOverMixed objects: [RealmBoundObject], execute block: (Realm, [RealmBoundObject]) -> ()) and users would need to call realm.async(handingOverMixed: [results, object]) { … } only when they wanted to hand over I think this is pretty gross, but there's not a great alternative. We could only keep the existential method, but then excessive casting is necessary to use the API. |
@austinzheng Do you have any clever workaround for the ambiguity here? If not, what do you suggest? |
What's wrong with just having the second API in option 1? (What's the use case for enforcing homogeneity again?) |
@austinzheng With only the existential API, users will always have to cast from the existential to the correct type. With the protocol constrained generic API, users will often not need to cast. realm.async(handingOver: [kim, tim]) { realm, people in
// existential API: `people: [RealmBoundObject]`
// constrained API: `people: [Person]`
} |
I see. I'll think about it. (I guess we don't want to go the cowards' route of just giving the methods slightly different names 😛.) |
I don't think that it's necessarily a bad idea to do that. |
Potential solution! 🎉 If we mark Unfortunately, you have to give the type checker needs some help in this case, but that's totally reasonable for the advanced use case of passing unrelated types. We should definitely document this though. realm.async(handingOver: [results, person] as [RealmBoundObject]) { realm, objects in
let results = objects[0] as! Results
let person = objects[1] as! Person
// do stuff async
} The user simply must add an What're your thoughts, @austinzheng? |
Oh, that's clever. And given that |
Exactly! And hopefully by the time we get a pure Swift API (like a bazillion years from now), Swift will conform its existential to their relevant protocol. |
Sounds like we'll go with the |
Is there a compelling use case for supporting async handover of Realm collections? #3828 only pertains to handover of Realm objects, but a logical extension is to support collections as well. There isn't however an easy way to expose such functionality without majorly complicating the API, so maybe it isn't something we should add unless there's a compelling reason?
The text was updated successfully, but these errors were encountered: