How to chain requests one after another using Promises -
i have create code login request consists of 4 steps:
- send username , password values url (http post) => response#1
- extract header info response#1 , send url (http get) => response#2
- extract , modify header info response#2 , send 3rd url (http get) => response#3
- if response#3 ok user data based on response#2 4th url => response#4
each of these steps can either fail or succeed.
steps can fail multiple ways (wrong status code, wrong response etc.)
what need way create function returns promise being resolved response#4 or rejected reason comes previous requests.
i writing in swift solution (language) accepted, i'll make fit swift
:)
here imagine great think it's not possible:
promise() { resolve, reject in //resolve(response#1) //reject(some reason) }.then(sendsecond) // can use response#1 .then(sendthird) // cannot use response#2 since isn't syncronous .then(sendfourth) // same sendthird
Comments
Post a Comment