-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_funkcije_MT.js
76 lines (63 loc) · 2.12 KB
/
04_funkcije_MT.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* -------------------------------------------------------------------------- */
// Copyright (c) 2021. Nikola Vukićević
/* -------------------------------------------------------------------------- */
function workerObradaPodataka(worker, e, lista) {
INDEKS_THREAD = e.data.i_primljeno;
if(INDEKS_THREAD == 0){
T1 = performance.now();
console.log(T1);
}
if(INDEKS_THREAD == lista.length - 1) {
T2 = performance.now();
ODZIV = T2 - T1 + "ms";
console.log(`Vreme obrade2: ${ODZIV}`);
}
let blok = document.getElementById(e.data.id);
//console.log(e.data.id)
//console.log(blok)
let listaTokena = e.data.listaTokena;
//console.log(listaTokena)
//console.log("----------------------------------------")
if(blok != null) {
blok.innerHTML = formatiranjeIspisListe(listaTokena, REZIM_ISPISA);
}
INDEKS_THREAD += KORAK;
if(INDEKS_THREAD < lista.length) {
worker.postMessage(
{
"i_poslato": INDEKS_THREAD ,
"id": lista[INDEKS_THREAD][3] ,
"tekst": lista[INDEKS_THREAD][2] ,
"definicijaJezika": lista[INDEKS_THREAD][0] ,
"rezim": REZIM_ISPISA
}
);
}
}
/* -------------------------------------------------------------------------- */
function definisanjeWorkera(worker, lista, i) {
worker.postMessage(
{
"i_poslato": i ,
"id": lista[i][3] ,
"tekst": lista[i][2] ,
"definicijaJezika": lista[i][0] ,
"rezim": REZIM_ISPISA
}
);
worker.onmessage = e => {
workerObradaPodataka(worker, e, lista);
}
}
/* -------------------------------------------------------------------------- */
function kreiranjeWorkera(lista) {
let listaWorkera = [];
for(let i = 0; i < BROJ_THREADOVA; i++) {
listaWorkera.push(new Worker('js/highlighter_worker.js'));
}
for(let i = 0; i < BROJ_THREADOVA; i++) {
let worker = new Worker('js/highlighter_worker.js');
definisanjeWorkera(worker, lista, i, workerObradaPodataka);
}
}
/* -------------------------------------------------------------------------- */