You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
callAsFunction could also be added to simplify this demo to:
lettodos=tryawaitgetTodos()
This opens up new opportunities for crafting readable APIs:
enumAPI{// These can be used as async throwing functions:staticletgetPosts= AnyRequest<[Post]>{Url("...")}staticletgetUsers= AnyRequest<[User]>{Url("...")}// Real functions can also be added:staticfunc getPost(id:Int)asyncthrows->Post{tryawait AnyRequest<Post>{Url(".../\(id)")}()}}// Simply use these as functions:letposts=tryawaitAPI.getPosts()letusers=tryawaitAPI.getUsers()letpost=tryawaitAPI.getPost(id:0)
The basic idea is that you can await any
Request
usingcall()
:callAsFunction
could also be added to simplify this demo to:This opens up new opportunities for crafting readable APIs:
async let
gives the power of concurrency:The text was updated successfully, but these errors were encountered: