JSFiddle - React, Tailwind, and code Playground
JavaScript
let channels = [
{
name: 'Chan1'
},
{
name: 'Chan2'
},
{
name: 'Chan3'
}
];
var promise1;
var promise2;
async function joinChannels () {
for (let channel of channels) {
await new Promise((resolve) => {
console.log('Joining channel ' + channel.name);
resolve(new Promise((resolve) => {
setTimeout(() => {
console.log('Done with channel ' + channel.name);
resolve();
}, 1000);
}));
});
}
}
function resetPromises() {
promise1 = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('connection');
}, 300);
});
promise2 = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('end song');
}, 900);
});
}
async function play(voiceChannels) {
for (let channel of voiceChannels) {
resetPromises();
console.log('Joining channel ' + channel.name);
await promise1.then(async (val) => {
console.log('Joined channel');
// dispatcher = connection.playFile('/home/pi/.discordbots/TARVIS/sncf.mp3');
await promise2.then((endSong) => {
console.log('Done playing');
});
});
}
}
/* joinChannels();*/
play(channels);