Erudaki Erudaki - 1 year ago 75
HTTP Question

.then handler being invoked out of order

My ultimate goal is to assign a chunk of database to class based object. To do this I am utilizing promises in typescript with the help of the

function to chain them. However I am running into brick walls.

return(, somepayload, someheaders)
.then(response => response.json())

However when this code executes the
before it gets the
which is causing issues in my program.

My question is, why are they occurring in that order and is there any way I can force them to execute in sequence?

Answer Source

You're calling MyCustomClass.function(MyObject), and passing the returned value to then(). What you actually want is to pass a function that, when called, will execute MyCustomClass.function(MyObject):

.then(() => {