Somehow I got in an infinite loop

I have this old code that worked well for a long time, but somehow it now gets stuck in an infinite loop:
let cmdsrelo = await botclient.stores.get("commands")
console.log("gotten cmdsrelo on shard " + botclient.shard.ids[0])
for (let [key, value] of cmdsrelo) {
value.reload()
}
let cmdsrelo = await botclient.stores.get("commands")
console.log("gotten cmdsrelo on shard " + botclient.shard.ids[0])
for (let [key, value] of cmdsrelo) {
value.reload()
}
In some commands I have a console log such as "find all / Search loaded." Those are printed constantly but the "gotten cmdsrelo on shard"... Is seemingly not printed.
7 Replies
bomi
bomi•13mo ago
Aha. Doing this as a work around prevents the infinite loop:
let counter = 0
console.log("gotten cmdsrelo on shard " + botclient.shard.ids[0])
for (let [key, value] of cmdsrelo) {
await sleep(5)
value.reload()
counter++
if (counter > 200) {
console.log("STOPPED Reloading commands on shard " + botclient.shard.ids[0])
break
}
}
let counter = 0
console.log("gotten cmdsrelo on shard " + botclient.shard.ids[0])
for (let [key, value] of cmdsrelo) {
await sleep(5)
value.reload()
counter++
if (counter > 200) {
console.log("STOPPED Reloading commands on shard " + botclient.shard.ids[0])
break
}
}
cmdsrelo.size is 110 but the for loop runs forever if it's not broken
Favna
Favna•13mo ago
first of all botclient.stores.get doesnt return a Promise so you can remove that await, it doesnt do anything. Secondly, it returns a Map so you should do
for (let [key, value] of cmdsrelo.entries()) {
value.reload();
]
for (let [key, value] of cmdsrelo.entries()) {
value.reload();
]
or better yet:
for (let value of cmdsrelo.values()) {
value.reload();
}
for (let value of cmdsrelo.values()) {
value.reload();
}
Lastly, if you use an external sharding manager (i.e. not DJS internal sharding) then you are responsible yourself for integrating that entirely within Sapphire as we do not add explicit support as there is simply no feasible way to support all sharding techniques.
kyra
kyra•13mo ago
If what you want is to load all commands, your entire thing gets resolved by doing a single line of code:
await container.stores.get('commands').loadAll();
await container.stores.get('commands').loadAll();
loadAll internally calls unloadAll, so it'll unload all the pieces as efficiently as possible, then load all pieces at once, also as efficiently. Reloading piece by piece in a loop has a large overhead since it doesn't batch the piece reloading, after all.
bomi
bomi•13mo ago
Thanks well Ill change that then, this has been working well for a long time but I guess times up Thank youu!
bomi
bomi•13mo ago
Also the reason this happened - ( because I updated sapphire?) is that I'm having a problem where broadcastEval blocks all the shards. Would it be okay to open a thread in #discordjs-support about that even thoguh I already made one in the discordJS server?
Favna
Favna•13mo ago
you wont really get better help here than in djs server tbh
bomi
bomi•13mo ago
oh 😭 But I think maybe it has just been slid down..