I have the following codes: First, it sends a package to the back-end using socket.emit, once it is done, initialize the chat
var socket = io();
send_package(socket, user_uid, match_uid, room_id, user_data).then(() => {
initializeChat(socket, user_uid, match_uid, room_id, user_data,
displayed_name, ll_location, ll_language, ll_level, ll_interests);
})
function send_package(socket, user_uid, match_uid, room_id, user_data) {
socket.on("connect", () => {
console.log("1");
socket.emit("match_package", {user_uid, match_uid, room_id, user_data});
})
return new Promise((resolve, reject) => {
if (true) {
resolve();
} else {
reject();
}
})
}
I feel that I did not use the promise correctly, because the initalizeChat function gets executed before send_package.
Your help and time is very appreciated.
Sincerely