mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 14:18:12 +02:00
made socket logic better
This commit is contained in:
@ -1,29 +1,21 @@
|
||||
import { io as socket } from "../socket.js";
|
||||
|
||||
export const evaluate_comments = async (answers) => {
|
||||
export const evaluate_comments = async (answers, percent_cb) => {
|
||||
const total = Object.keys(answers).length;
|
||||
let i = 0;
|
||||
for (const [key, value] of Object.entries(answers)) {
|
||||
console.log(`Processing ${key}: ${value}...`);
|
||||
await new Promise((res) => setTimeout(res, 500));
|
||||
await new Promise((res) => setTimeout(res, 1000));
|
||||
console.log("Done");
|
||||
const data = {
|
||||
percent: Math.floor((++i / total) * 100),
|
||||
};
|
||||
socket.emit("progress", data);
|
||||
percent_cb(Math.floor((++i / total) * 100));
|
||||
}
|
||||
};
|
||||
|
||||
export const evaluate_refinement = async (answers) => {
|
||||
export const evaluate_refinement = async (answers, percent_cb) => {
|
||||
const total = Object.keys(answers).length;
|
||||
let i = 0;
|
||||
for (const [key, value] of Object.entries(answers)) {
|
||||
console.log(`Processing ${key}: ${value}...`);
|
||||
await new Promise((res) => setTimeout(res, 500));
|
||||
await new Promise((res) => setTimeout(res, 1000));
|
||||
console.log("Done");
|
||||
const data = {
|
||||
percent: Math.floor((++i / total) * 100),
|
||||
};
|
||||
socket.emit("progress", data);
|
||||
percent_cb(Math.floor((++i / total) * 100));
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user