What is the easiest way to implement the same behaviour on Android? I mean I would like to have my thread (not main) wait for network operations and execute them one after another. In javascript, there is simple way to implement this behaviour thanks to Promise.
exports.someFunction = functions.https.onRequest((req, res) => {
const userId = req.query.user
//long time
ref.orderByChild("parentId").equalTo(userId)
.on("value", function (snapshot) {
if (snapshot.val() === null) {
res.status(402)
return
}
snapshot.forEach(function (childSnapshot) {
const foo = childSnapshot.val();
getAccessToken().then(fistResponse => {
var json = JSON.parse(fistResponse);
accToken = json.access_token;
getMoreInformation(accToken, foo.bar).then(response => {
console.log(response)
if (isValid(response)) {
res.status(200)
} else {
res.status(402)
}
})})})})});
Currently I am using interface, but I would like to learn other way.
I found there is something like Future in android and that is probably what I am looking for.