Code Monkey home page Code Monkey logo

Comments (6)

3lvis avatar 3lvis commented on June 14, 2024

HiI! Right now we only have "unauthorizedRequestCallback", it gets called when a 403 is triggered so you can renew your token.

https://github.com/3lvis/Networking/blob/master/Sources/Networking.swift#L169

I think we could do better, though. What are your thoughts on the current solution?

from networking.

codeOfRobin avatar codeOfRobin commented on June 14, 2024

🤔 Is it called for all requests? If so, In theory, you could put in a couple of NSLocks and initiate retrials for all the requests after getting a new token, right?

from networking.

3lvis avatar 3lvis commented on June 14, 2024

That could work 🤔.

I guess that's the biggest missing piece at the moment, the retrials after the token part. I guess ideally you have all the requests in a queue and if you get a 403, you stop all the requests in the queue until the token is renewed, then you restart the pending requests.

from networking.

codeOfRobin avatar codeOfRobin commented on June 14, 2024

all the requests in a queue

You mean in a concurrent queue, correct? Doesn't URLSession do that by default?

from networking.

3lvis avatar 3lvis commented on June 14, 2024

We could probably use that one

https://developer.apple.com/documentation/foundation/urlsession/1411597-init

from networking.

codeOfRobin avatar codeOfRobin commented on June 14, 2024

@3lvis how about we have a post and a pre-response hook for all requests? That way, you don't execute a completion block (like in https://github.com/3lvis/Networking/blob/master/Sources/Networking%2BHTTPRequests.swift#L13 )

until the post commit hook is completed. If you have a 401 with an expired token, execute a lock.lock*(), and refresh your tokens. Once your token is refreshed, retry the request (not quite sure how you'd do that)

I've also been considering implementing this an Rx extension to Networking (imagine having a shared observable and every request using the retry operator with it. It could also be used in conjunction with Rx's smart retry policies

from networking.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.