Now this is the case, function a returns data asynchronously from Promise, and many other functions need to use this data. Now I have to process a().then() like this for every function that relies on this data
function a() {
return new Promise((resolve, reject) => {
....
})
}
function getsub(id) {
return a()
.then((data) => {
return .....
})
.catch((err) => {...})
}
function tree(id) {
return a()
.then((data) => {
return .....
})
.catch((err) => {...})
}
There are some recursive cyclic dependencies. When the complexity increases, I feel like I am going crazy. Is there any other better way to write it?
You can use functional programming to write:
Try ES7's async/await?
Or introduce the async.js library, which is common to both front and back ends.
If the real-time and independence requirements are very high, there seems to be no solution... Otherwise, you can try caching a... and see what other people say