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

Implement a URLSession backend for viaduct on iOS #1326

Closed
rfk opened this issue Jun 26, 2019 · 4 comments
Closed

Implement a URLSession backend for viaduct on iOS #1326

rfk opened this issue Jun 26, 2019 · 4 comments

Comments

@rfk
Copy link
Contributor

rfk commented Jun 26, 2019

This was mentioned in slack last week, wanted to file it for future reference.

Our networking library currently uses hyper on iOS, which bottoms out at the system networking and TLS stack, but brings with it a bunch of intermediate dependencies. We should consider doing a thin viaduct backend that directly uses the native URLSession infrastructure provided by the platform, which would reduce dependency footprint and simplify reasoning about the system.

┆Issue is synchronized with this Jira Task

@rfk
Copy link
Contributor Author

rfk commented Jun 26, 2019

/cc @garvankeeley @thomcc; no particular urgency here IIUC, but worth thinking about.

@thomcc
Copy link
Contributor

thomcc commented Jun 26, 2019

This doesn't sound hard. The same backend as for the android code could hopefully be used, just with swift powering it rather than Kotlin. The one caveat is that the API exposed by viaduct backends must be synchronous, whereas URLSession is async.

That said, swift has some locks and stuff even if it's much more limited than rust there, so we can hopefully make that work.

@garvankeeley
Copy link
Contributor

garvankeeley commented Jun 26, 2019

Happy to help.
Quick tip for URLSession, instantiate it with the arg delegateQueue: .main, so that the response calls back to main (default behaviour is off-main response calls).
More relevant, IIUC we want a sync urlsession wrapper implementation which should be trivial on the swift side (pseudocode):

// got called from rust to load an url
semaphore.setup()
urlSession.dataTask(url: url) { data, error in
    // got data or error
    semaphore.notify()
}
semaphore.wait()
// go back to rust with data and error state info

@rfk
Copy link
Contributor Author

rfk commented Jun 26, 2019

Would it make sense to allow the caller to pass in a URLSession instance in a similar way to how a-c can pass in a specific Fetch implementation?

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

4 participants