-
Notifications
You must be signed in to change notification settings - Fork 52
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
[ffigen] Support blocking callbacks #1647
Comments
@liamappelbe Can you point me at an example of this type of API? |
The one Brian ran into in cupertino_http was URLSession:downloadTask:didFinishDownloadingToURL:. It's called after a download to a temporary file is complete. The temporary file will be deleted after the callback returns. So if you want to do something with the file, your callback has to be blocking. @brianquinlan What were the other examples you found that were using the completion handler pattern, but expect the completion handler to be called during the callback? |
We're auto-converting all delegate protocols to callbacks still, right? If so, this is not going to be rare. Having a delegate to provide data or synchronous decisions is fairly common pattern. |
I didn't look very hard for examples. |
Turns out there are a few Apple APIs that require that the completion handler is invoked during the callback. So we should add a variant of listener blocks and protocol methods that uses a mutex to block until the listener callback is complete.
NativeCallable.isolateLocal
style).With a little more infrastructure, it would also be possible to support callbacks that return results, but these are even rarer in Apple APIs, so we'll wait until we have a use case for this.
The text was updated successfully, but these errors were encountered: