This is part of code (code not mine, I can't understand how it's working, maybe it's called Promise, but I'm not sure).
m = {
mounted: function() {
var e = this;
this.$bus.on("buff-event", (function(t) {
e.buff(t)
}))
},
methods: {
buff: function(e) {
var t = this;
this.$bus.emit("bfceebecbb-change", "Motivating...");
var n = '[{"__class__":"ServerRequest","requestData":[],"requestClass":"OtherPlayerService","requestMethod":"' + e + '","requestId":%%requestId%%}]';
this.requestFaker.fetch(n).then((function(i) {
i = (i = i.filter((function(t) {
return t.requestMethod == e
}))[0]).responseData.filter((function(e) {
return void 0 === e.next_interaction_in && !e.is_self && (void 0 === e.accepted || 1 == e.accepted)
})), n = [], _.forEach(i, (function(e) {
n.push('{"__class__":"ServerRequest","requestData":[' + e.player_id + '],"requestClass":"OtherPlayerService","requestMethod":"polivateRandomBuilding","requestId":%%requestId%%}')
})), n.length ? (n = "[" + n.join(",") + "]", t.requestFaker.fetch(n).then((function() {
t.$bus.emit("bfceebecbb-change", "Motivation success")
}))) : t.$bus.emit("bfceebecbb-change", "Nobody to motivate")
}))
}
}
},
This code collecting data of users, store in to array and then pass it to the server. So it sending big array of all users in one request (it pushing all entries to array in this part n.push('{"__class__":"ServerRequest"...).
What I want to achieve is to send requests for each user one by one with some delays (for example 1 second delay between requests).
I've tried many ways to achieve it, but all unsuccessfully, I'm lack of knowledge about this programming language.
I've tried to use setTimeout functions in different ways, but all the time unsuccessfully:
methods: {
buff: function(e) {
var t = this;
this.$bus.emit("bfceebecbb-change", "Motivating...");
var n = '[{"__class__":"ServerRequest","requestData":[],"requestClass":"OtherPlayerService","requestMethod":"' + e + '","requestId":%%requestId%%}]';
this.requestFaker.fetch(n).then((function(i) {
i = (i = i.filter((function(t) {
return t.requestMethod == e
}))[0]).responseData.filter((function(e) {
return void 0 === e.next_interaction_in && !e.is_self && (void 0 === e.accepted || 1 == e.accepted)
})), n = [], _.forEach(i, (function(e) {
n.push('{"__class__":"ServerRequest","requestData":[' + e.player_id + '],"requestClass":"OtherPlayerService","requestMethod":"polivateRandomBuilding","requestId":%%requestId%%}')
})), n.length ?
setTimeout((function() {
(setTimeout((function() {n = "[" + n.join(",") + "]"}), 1000) , t.requestFaker.fetch(n).then((function() {
t.$bus.emit("bfceebecbb-change", "Motivation success")
})))}), 1000) : t.$bus.emit("bfceebecbb-change", "Nobody to motivate")
}))
}
}
Also tried like this:
methods: {
buff: function(e) {
var t = this;
this.$bus.emit("bfceebecbb-change", "Motivating...");
var n = '[{"__class__":"ServerRequest","requestData":[],"requestClass":"OtherPlayerService","requestMethod":"' + e + '","requestId":%%requestId%%}]';
this.requestFaker.fetch(n).then((function(i) {
i = (i = i.filter((function(t) {
return t.requestMethod == e
}))[0]).responseData.filter((function(e) {
return void 0 === e.next_interaction_in && !e.is_self && (void 0 === e.accepted || 1 == e.accepted)
})), n = [], _.forEach(i, (function(e) {
n.push('{"__class__":"ServerRequest","requestData":[' + e.player_id + '],"requestClass":"OtherPlayerService","requestMethod":"polivateRandomBuilding","requestId":%%requestId%%}')
})), n.length ?
setTimeout((function() {
(n = "[" + n.join(",") + "]", t.requestFaker.fetch(n).then((function() {
t.$bus.emit("bfceebecbb-change", "Motivation success")
})))}), 1000) : t.$bus.emit("bfceebecbb-change", "Nobody to motivate")
}))
}
}
UPDATED
As per comment asked what is %%requestId%% - I found this part:
{
key: "fetch",
value: function(e) {
function t(t) {
return e.apply(this, arguments)
}
return t.toString = function() {
return e.toString()
}, t
}((function(e) {
for (var t = e;
(t = e.replace("%%requestId%%", this.requestId)) !== e;) e = t, this.incRequestId();
return fetch(gameVars.gatewayUrl, this.getHeadForFetchQuery(e)).then((function(e) {
return e.json()
}))
}))
}
%%requestId%%?%%requestId%%". I have no idea what it means and why it's used here. I copy > pasted code between{ }, but there is much bigger function, if this part is not enough I can paste here entire function.