{"id":36774,"date":"2019-10-31T22:13:44","date_gmt":"2019-10-31T19:13:44","guid":{"rendered":"https:\/\/prohoster.info\/blog\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs\/"},"modified":"2019-10-31T22:13:44","modified_gmt":"2019-10-31T19:13:44","slug":"asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs","status":"publish","type":"post","link":"https:\/\/prohoster.info\/sq\/blog\/novosti-interneta\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs","title":{"rendered":"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>P\u00ebrsh\u00ebndetje t\u00eb gjith\u00ebve. K\u00ebtu \u00ebsht\u00eb Omelnytskiy Serhiy. Para pak kohe mbajta nj\u00eb transmetim p\u00ebr programimin reaktiv, ku flas p\u00ebr asinkronitetin n\u00eb JavaScript. Sot do doja t\u00eb p\u00ebrmbledh k\u00ebt\u00eb material. <\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/11acf6af8328d3deb6f0ce48e813efb7.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>Por para se t\u00eb fillojm\u00eb me materialin kryesor, na nevojitet nj\u00eb hyrje. Le t\u00eb fillojm\u00eb me definita: \u00e7far\u00eb \u00ebsht\u00eb staku dhe radhitja?<br \/>\n<strong>Staku <\/strong>\u2014 \u00ebsht\u00eb nj\u00eb koleksion, elementet e t\u00eb cilit merret sipas parimit \"i fundit i hyr\u00eb, i pari i dal\u00eb\" LIFO<br \/>\n<strong>Radhitja <\/strong>\u2014 \u00ebsht\u00eb nj\u00eb koleksion, elementet e t\u00eb cilit merret sipas parimit \"i pari i hyr\u00eb, i pari i dal\u00eb\" FIFO<\/p>\n<p><\/p>\n<p>Mir\u00eb, t\u00eb vazhdojm\u00eb. <\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/a7d64d1c74f37b463869dd57b96c9d0e.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>JavaScript \u00ebsht\u00eb nj\u00eb gjuh\u00eb programimi nj\u00ebp\u00ebrmasore. Kjo do t\u00eb thot\u00eb se ka vet\u00ebm nj\u00eb rrjedh\u00eb ekzekutimi dhe nj\u00eb stok, n\u00eb t\u00eb cilin vendosen funksionet n\u00eb radh\u00eb p\u00ebr ekzekutim. Si pasoj\u00eb, n\u00eb nj\u00eb moment t\u00eb vet\u00ebm JavaScript mund t\u00eb ekzekutoj\u00eb vet\u00ebm nj\u00eb operacion, operacione t\u00eb tjera do t\u00eb presin n\u00eb radh\u00eb derisa t\u00eb thirren. <\/p>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<p><strong>Staku i thirrjeve<\/strong> \u2014 \u00ebsht\u00eb nj\u00eb struktur\u00eb t\u00eb dh\u00ebnash q\u00eb, n\u00eb terma t\u00eb thjesht\u00eb, regjistron informacionin mbi vendin n\u00eb program ku ndodhemi. N\u00ebse kalojm\u00eb n\u00eb nj\u00eb funksion, ne vendosim nj\u00eb regjistrim p\u00ebr t\u00eb n\u00eb maj\u00eb t\u00eb stack-ut. Kur kthehemi nga funksioni, ne nxjerrim elementin m\u00eb t\u00eb lart\u00eb nga stack-u dhe p\u00ebrfundojm\u00eb atje ku e kemi thirrur k\u00ebt\u00eb funksion. Kjo \u00ebsht\u00eb e gjitha q\u00eb mund t\u00eb b\u00ebj\u00eb stack-u. Tani nj\u00eb pyetje mjaft interesante. Si funksionon at\u00ebher\u00eb asinkroniciteti n\u00eb JavaScript?<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/a29fd1dd3de06fb203c7dd14bda30548.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>N\u00eb t\u00eb v\u00ebrtet\u00eb, p\u00ebrve\u00e7 stack-ut, n\u00eb shfletues ka nj\u00eb radh\u00eb t\u00eb ve\u00e7ant\u00eb p\u00ebr t\u00eb punuar me at\u00eb q\u00eb quhet WebAPI. Funksionet nga kjo radh\u00eb do t\u00eb ekzekutohen n\u00eb rend\u00ebsi vet\u00ebm pasi stack-u t\u00eb jet\u00eb plot\u00ebsisht i zbraz\u00ebt. Vet\u00ebm pas k\u00ebsaj ato vendosen nga radh\u00eb n\u00eb stack p\u00ebr t'u ekzekutuar. N\u00ebse n\u00eb stack aktualisht ndodhet t\u00eb pakt\u00ebn nj\u00eb element, ato nuk mund t\u00eb hyjn\u00eb n\u00eb stack. Pik\u00ebrisht p\u00ebr k\u00ebt\u00eb arsye thirrjet e funksioneve me timeout shpesh nuk jan\u00eb t\u00eb sakta n\u00eb koh\u00eb, sepse funksioni nuk mund t\u00eb hyj\u00eb nga radh\u00eb n\u00eb stack derisa ai t\u00eb jet\u00eb i plot\u00eb. <\/p>\n<p><\/p>\n<p>Le t\u00eb shqyrtojm\u00eb shembullin e m\u00ebposht\u00ebm dhe t\u00eb merremi me \"ekzekutimin\" e tij hap pas hapi. Po ashtu, do t\u00eb shikojm\u00eb se \u00e7far\u00eb ndodh n\u00eb sistem gjat\u00eb k\u00ebsaj procedure.<\/p>\n<p><\/p>\n<pre><code class=\"javascript\">console.log('Hi);\nsetTimeout(function cb1() {\n    console.log('cb1');\n}, 5000);\nconsole.log('Bye');<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/379423fca95fb28b2124be03dfd15739.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>1) Deri asnj\u00eb gj\u00eb. Konsola e shfletuesit \u00ebsht\u00eb e past\u00ebr, staku i thirrjeve \u00ebsht\u00eb i zbraz\u00ebt.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/4a16bbc23bade54ae0b02d81d5f6a581.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>2) \u041f\u043e\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;Hi&#8217;)\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/a1845af23fd7dedebf94afc168f1f13f.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>3) Dhe ajo ekzekutohet.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/57397b53386018b662f3a79a6d4d60fb.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>4) \u0417\u0430\u0442\u0435\u043c console.log(&#8216;Hi&#8217;) \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/7cb2b32be8807ecf39d2f38683ccd435.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>5) Tani kalojm\u00eb te komanda setTimeout(function cb1() {\u2026 }). Ajo shtohet n\u00eb stakun e thirrjeve.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/99c0724994e3390d009577852b451beb.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>6) Komanda setTimeout(function cb1() {\u2026 }) ekzekutohet. Shfletuesi krijon nj\u00eb timer q\u00eb \u00ebsht\u00eb pjes\u00eb e Web API. Ai do t\u00eb b\u00ebj\u00eb num\u00ebrimin mbrapsht.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/99086cdeafd83c5fe72e92c4a9f9b738.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>7) Komanda setTimeout(function cb1() {\u2026 }) p\u00ebrfundon dhe hiqet nga staku i thirrjeve.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/24ac12b1b6cfbff780ece9e9a7acd7c7.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>8) \u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;Bye&#8217;)\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/6ccad0ad8eebf05e870a409766d38766.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>9) \u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;Bye&#8217;)\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/09e4e380eb873fb23bea550f3ffb21f7.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>10) \u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;Bye&#8217;)\u00a0\u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/357bfb372361310681ba7bb1860d90d7.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>11) Pasi t\u00eb kalojn\u00eb, t\u00eb pakt\u00ebn, 5000 ms., timer-i p\u00ebrfundojn\u00eb dhe vendos kolb-bekimin cb1 n\u00eb radh\u00ebn e kolb-bekimeve.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/8170e8ff5d3d0c56c0091658370c25cc.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>12) Cikli i ngjarjeve merr funksionin cb1 nga radh\u00eb e kolb-bekimeve dhe e vendos at\u00eb n\u00eb stakun e thirrjeve.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/d858a54e82bc32d84f854610db462bc1.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>13) \u0424\u0443\u043d\u043a\u0446\u0438\u044f\u00a0cb1\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u00a0console.log(&#8216;cb1&#8217;)\u00a0\u0432 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/6ca8e016389904eec57035e64d57a157.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>14) \u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;cb1&#8217;)\u00a0\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/0caa645a90ac1fca5fb8a76569494d48.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>15) \u041a\u043e\u043c\u0430\u043d\u0434\u0430\u00a0console.log(&#8216;cb1&#8217;)\u00a0\u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/aeb838fe8df3f6e3f8603a4207a6e193.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>16) Funksioni cb1 hiqet nga staku i thirrjeve.<\/p>\n<p><\/p>\n<p>Shikojm\u00eb nj\u00eb shembull n\u00eb dinamik\u00eb:<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/3836d9df513afee374f498720990e39f.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>Tani q\u00eb kemi shqyrtuar se si \u00ebsht\u00eb implementuar asinkronia n\u00eb JavaScript, le t\u00eb flasim shkurtimisht mbi evolucionin e kodit asinkron.<\/p>\n<p><\/p>\n<h2 id=\"evolyuciya-asinhronnogo-koda\">Evolucioni i kodit asinkron.<\/h2>\n<p><\/p>\n<pre><code class=\"javascript\">a(function (resultsFromA) {\n    b(resultsFromA, function (resultsFromB) {\n        c(resultsFromB, function (resultsFromC) {\n            d(resultsFromC, function (resultsFromD) {\n                e(resultsFromD, function (resultsFromE) {\n                    f(resultsFromE, function (resultsFromF) {\n                        console.log(resultsFromF);\n                    })\n                })\n            })\n        })\n    })\n});<\/code><\/pre>\n<p><\/p>\n<p>Programimi asinkron, si\u00e7 e dim\u00eb ne JavaScript, mund t\u00eb implementohet vet\u00ebm me funksione. Ato mund t\u00eb kalohen si \u00e7do variab\u00ebl tjet\u00ebr n\u00eb funksione t\u00eb tjera. K\u00ebshtu lind\u00ebn callback-\u00ebt. Dhe kjo \u00ebsht\u00eb arg\u00ebtuese dhe g\u00ebzuese derisa t\u00eb shnd\u00ebrrohet n\u00eb trishtim, m\u00ebrzi dhe breng\u00eb. Pse? Sepse \u00ebsht\u00eb shum\u00eb e thjesht\u00eb:<\/p>\n<p><\/p>\n<ul>\n<li>Me rritjen e kompleksitetit t\u00eb kodit, projekti shpejt shnd\u00ebrrohet n\u00eb blloqe t\u00eb thelluara t\u00eb paqart\u00eb - \"callback hell\".<\/li>\n<li>P\u00ebrpunimi i gabimeve leht\u00ebsisht mund t\u00eb humbas\u00eb.<\/li>\n<li>Nuk \u00ebsht\u00eb e mundur t\u00eb kthehen shprehje me return.<\/li>\n<\/ul>\n<p><\/p>\n<p>Me ardhjen e Promise, situata u b\u00eb pak m\u00eb e mir\u00eb.<\/p>\n<p><\/p>\n<pre><code class=\"javascript\">new Promise(function(resolve, reject) {\n    setTimeout(() =&gt; resolve(1), 2000);\n\n}).then((result) =&gt; {\n    alert(result);\n    return result + 2;\n\n}).then((result) =&gt; {\n    throw new Error('FAILED HERE');\n    alert(result);\n    return result + 2;\n\n}).then((result) =&gt; {\n    alert(result);\n    return result + 2;\n\n}).catch((e) =&gt; {\n    console.log('error: ', e);\n});<\/code><\/pre>\n<p><\/p>\n<ul>\n<li>Me shfaqen zinxhir\u00eb promisesh, q\u00eb e p\u00ebrmir\u00ebsojn\u00eb lexueshm\u00ebrin\u00eb e kodit<\/li>\n<li>Shfaqet nj\u00eb metod\u00eb e ve\u00e7ant\u00eb p\u00ebr kapjen e gabimeve<\/li>\n<li>Shfaqet mund\u00ebsia e ekzekutimit paralel me ndihm\u00ebn e Promise.all<\/li>\n<li>Asinhron\u00ebsin\u00eb e brendshme mund ta zgjidhim me async\/await<\/li>\n<\/ul>\n<p><\/p>\n<p>Por promesa ka kufizimet e saj. P\u00ebr shembull, nj\u00eb promise, pa ndonj\u00eb marr\u00ebveshje t\u00eb ve\u00e7ant\u00eb, nuk mund t\u00eb anulohet, dhe m\u00eb e r\u00ebnd\u00ebsishmja \u2014 punon vet\u00ebm me nj\u00eb vler\u00eb.<\/p>\n<p><\/p>\n<p>Tani ne kemi arritur smooth n\u00eb programimin reaktiv. A jeni t\u00eb lodhur? Mir\u00eb, mund t\u00eb shkoni t\u00eb b\u00ebni nj\u00eb \u00e7aj, t\u00eb mendoni dhe t\u00eb ktheheni p\u00ebr t\u00eb lexuar m\u00eb tej. Un\u00eb do t\u00eb vazhdoj.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/48409ec625d57fec171214c1de332c85.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Programimi reaktiv<\/strong>\u200a\u2014\u200anj\u00eb paradigme programimi q\u00eb \u00ebsht\u00eb e orientuar nga rrjedhat e t\u00eb dh\u00ebnave dhe shp\u00ebrndarjen e ndryshimeve. Le t\u00eb shqyrtojm\u00eb m\u00eb n\u00eb detaje se \u00e7far\u00eb \u00ebsht\u00eb rrjedha e t\u00eb dh\u00ebnave.<\/p>\n<p><\/p>\n<pre><code class=\"javascript\">\/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\nconst input = ducument.querySelector('input');\n\nconst eventsArray = [];\n\n\/\/ \u041f\u0443\u0448\u0438\u043c \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 eventsArray\ninput.addEventListener('keyup',\n    event =&gt; eventsArray.push(event)\n);<\/code><\/pre>\n<p><\/p>\n<p>Imagjinoni se kemi nj\u00eb fush\u00eb hyr\u00ebse. Ne krijojm\u00eb nj\u00eb masiv dhe p\u00ebr \u00e7do ngjarje keyup t\u00eb inputit do t\u00eb ruajm\u00eb ngjarjen n\u00eb masivin ton\u00eb. D\u00ebshirojm\u00eb t\u00eb theksojm\u00eb se masivi yn\u00eb \u00ebsht\u00eb renditur sipas koh\u00ebs, pra indeksi i ngjarjeve m\u00eb t\u00eb vona \u00ebsht\u00eb m\u00eb i madh se indeksi i atyre m\u00eb t\u00eb hershme. Ky masiv p\u00ebrfaq\u00ebson nj\u00eb model t\u00eb thjeshtuar t\u00eb rrjedhjes s\u00eb t\u00eb dh\u00ebnave, por nuk \u00ebsht\u00eb ende nj\u00eb rrjedh\u00eb. P\u00ebr ta quajtur k\u00ebt\u00eb masiv me siguri nj\u00eb rrjedh\u00eb, ai duhet t\u00eb dij\u00eb se si t'i informoj\u00eb abonuesit p\u00ebr t\u00eb dh\u00ebnat e reja q\u00eb jan\u00eb marr\u00eb. K\u00ebshtu arrit\u00ebm n\u00eb p\u00ebrcaktimin e rrjedh\u00ebs.<\/p>\n<p><\/p>\n<h3 id=\"potok-dannyh\">Shkalla e t\u00eb dh\u00ebnave<\/h3>\n<p><\/p>\n<pre><code class=\"javascript\">const { interval1 } = Rx;\nconst { take } = RxOperators;\n\ninterval(1000).pipe(\n    take(4)\n)<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/68ec447abafb6b8a323b429ed94f8252.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Rrjedha<\/strong>\u00ebsht\u00eb nj\u00eb masiv t\u00eb dh\u00ebnash t\u00eb renditura sipas koh\u00ebs, i cili mund t'i njoftoj\u00eb se t\u00eb dh\u00ebnat kan\u00eb ndryshuar. Tani imagjinoni sa e leht\u00eb \u00ebsht\u00eb t\u00eb shkruani kod, ku p\u00ebr nj\u00eb veprim duhet t\u00eb th\u00ebrrisni disa ngjarje n\u00eb pjes\u00eb t\u00eb ndryshme t\u00eb kodit. Ne thjesht b\u00ebjm\u00eb nj\u00eb abonim n\u00eb rrjedh\u00eb dhe ajo na informon vet\u00eb kur ndodhin ndryshimet. K\u00ebt\u00eb e b\u00ebn biblioteka RxJs.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/dcb1cfca8b4d8a887b63c302a7d6c06a.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>RxJS <\/strong> \u2014 \u00ebsht\u00eb nj\u00eb bibliotek\u00eb p\u00ebr t\u00eb punuar me programe asinkrone dhe t\u00eb bazuara n\u00eb ngjarje duke p\u00ebrdorur sekuenca t\u00eb v\u00ebzhguara. Biblioteca ofron tipin kryesor <em>Observable<\/em>, disa lloje ndihm\u00ebse (<em>Observer, Schedulers, Subjects<\/em>) dhe operator\u00eb p\u00ebr t\u00eb punuar me ngjarjet si me koleksionet (<em>map, filter, reduce, every<\/em> dhe t\u00eb ngjashme nga JavaScript Array).<\/p>\n<p><\/p>\n<p>Le t\u00eb shqyrtojm\u00eb konceptet kryesore t\u00eb k\u00ebsaj biblioteke.<\/p>\n<p><\/p>\n<h3 id=\"observable-observer-producer\">Observable, Observer, Producer<\/h3>\n<p><\/p>\n<p>Observable \u00ebsht\u00eb tipi i par\u00eb baz\u00eb q\u00eb do t\u00eb shqyrtojm\u00eb. Ky klas p\u00ebrmban pjes\u00ebn kryesore t\u00eb implementimit t\u00eb RxJs. Ai \u00ebsht\u00eb i lidhur me fluxin e v\u00ebzhguar, n\u00eb t\u00eb cilin mund t\u00eb abonoheni p\u00ebrmes metod\u00ebs subscribe.<\/p>\n<p><\/p>\n<p>N\u00eb Observable implementohet nj\u00eb mekaniz\u00ebm ndihm\u00ebs p\u00ebr krijimin e azhurnimeve, e ashtuquajtura <em>Observer<\/em>. Burimi i vlerave p\u00ebr Observer quhet <em>Prodhues<\/em>. Kjo mund t\u00eb jet\u00eb nj\u00eb array, nj\u00eb iterues, web socket, nj\u00eb ngjarje etj. Pra, mund t\u00eb thuhet se observable \u00ebsht\u00eb nj\u00eb lidh\u00ebs midis Producer dhe Observer. <\/p>\n<p><\/p>\n<p>Observable p\u00ebrpunon tri lloje ngjarjesh p\u00ebr Observer:<\/p>\n<p><\/p>\n<ul>\n<li>next \u2013 t\u00eb dh\u00ebna t\u00eb reja<\/li>\n<li>error \u2013 nj\u00eb gabim, n\u00ebse sekuenca p\u00ebrfundoi p\u00ebr shkak t\u00eb nj\u00eb situate p\u00ebrjashtimi. Ky ngjarje gjithashtu presupozon p\u00ebrfundimin e sekuenc\u00ebs.<\/li>\n<li>komplet - sinjali i p\u00ebrfundimit t\u00eb sekuenc\u00ebs. Kjo do t\u00eb thot\u00eb se nuk do t\u00eb ket\u00eb m\u00eb t\u00eb dh\u00ebna t\u00eb reja<\/li>\n<\/ul>\n<p><\/p>\n<p>T\u00eb shohim nj\u00eb demo:<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/c5bcd2af0f18b6de3ab0dbc20db595d1.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>N\u00eb fillim do t\u00eb p\u00ebrpunojm\u00eb vlerat 1, 2, 3, dhe pas 1 sek. do t\u00eb marrim 4 dhe do t\u00eb p\u00ebrfundojm\u00eb stream-in ton\u00eb.<\/p>\n<p>\n<b class=\"spoiler_title\">T\u00eb mendojm\u00eb n\u00eb z\u00eb<\/b><\/p>\n<p>Dhe k\u00ebtu e kuptova se ishte m\u00eb interesant t\u00eb tregoja se sa t\u00eb shkruaja p\u00ebr k\u00ebt\u00eb. \ud83d\ude00 <\/p>\n<p><\/p>\n<h3 id=\"subscription\">Abonim<\/h3>\n<p><\/p>\n<p>Kur ne b\u00ebjm\u00eb nj\u00eb abonim n\u00eb stream, krijojm\u00eb nj\u00eb klas\u00eb t\u00eb re <strong>subscription<\/strong>, e cila na jep mund\u00ebsin\u00eb t\u00eb anulojm\u00eb abonimin me metod\u00ebn <em>unsubscribe<\/em>. Gjithashtu, mund t\u00eb grumbullojm\u00eb abonimet me metod\u00ebn <em>shto<\/em>. Dhe \u00ebsht\u00eb logjike q\u00eb mund t\u00eb shk\u00ebpusim stream-et me <em>remove<\/em>. Metodat add dhe remove pranojn\u00eb nj\u00eb abonim t\u00eb tjet\u00ebr si argument. D\u00ebshiroj t\u00eb theksoj se kur ne b\u00ebjm\u00eb anullimin, ne anulojm\u00eb t\u00eb gjitha abonimet f\u00ebmij\u00eb si\u00e7 do t\u00eb thoshim se ato do t\u00eb th\u00ebrrisnin metod\u00ebn unsubscribe. T\u00eb vazhdojm\u00eb m\u00eb tej.<\/p>\n<p><\/p>\n<h3 id=\"vidy-potokov\">Llojet e stream-eve<\/h3>\n<p><\/p>\n<table>\n<thead>\n<tr>\n<th>Nxeht\u00eb<\/th>\n<th>Ftoht\u00eb<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Prodhuese krijohet jasht\u00eb observable<\/td>\n<td>Prodhuese krijohet brenda observable<\/td>\n<\/tr>\n<tr>\n<td>T\u00eb dh\u00ebnat transmetohen n\u00eb momentin e krijimit t\u00eb observable<\/td>\n<td>T\u00eb dh\u00ebnat komunikohen n\u00eb momentin e abonimit<\/td>\n<\/tr>\n<tr>\n<td>Nevojitet logjik\u00eb shtes\u00eb p\u00ebr anulimin<\/td>\n<td>Stream-i p\u00ebrfundon vet\u00eb<\/td>\n<\/tr>\n<tr>\n<td>P\u00ebrdor lidhjen nj\u00eb-n\u00eb-shum\u00eb<\/td>\n<td>P\u00ebrdor lidhjen nj\u00eb-n\u00eb-nj\u00eb<\/td>\n<\/tr>\n<tr>\n<td>T\u00eb gjitha abonimet kan\u00eb nj\u00eb vler\u00eb t\u00eb vetme<\/td>\n<td>Abonimet jan\u00eb t\u00eb pavarura<\/td>\n<\/tr>\n<tr>\n<td>T\u00eb dh\u00ebnat mund t\u00eb humbasin n\u00ebse nuk ka subscription<\/td>\n<td>Rindez t\u00eb gjitha vlerat e rrjedh\u00ebs p\u00ebr nj\u00eb abonim t\u00eb ri<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<p>N\u00ebse do t\u00eb b\u00ebnim nj\u00eb krahasim, do ta p\u00ebrshkruaja rrjedh\u00ebn e ngroht\u00eb si nj\u00eb film n\u00eb kinema. N\u00eb momentin kur ke hyr\u00eb, aty e ke filluar shikimin. Rrjedh\u00ebn e ftoht\u00eb do ta krahasoja me nj\u00eb telefonat\u00eb n\u00eb mb\u00ebshtetje teknike. \u00c7do person q\u00eb telefonon do t\u00eb d\u00ebgjoj\u00eb regjistrimin e automatik\u00ebs nga fillimi deri n\u00eb fund, por ti mund t\u00eb nd\u00ebrpres\u00ebsh telefonat\u00ebn duke u unsubscribe.<\/p>\n<p><\/p>\n<p>D\u00ebshiroj t\u00eb theksoj se ekzistojn\u00eb edhe rrjedha t\u00eb ashtuquajtura t\u00eb ngrohta (k\u00ebt\u00eb definicion e kam hasur jasht\u00ebzakonisht rrall\u00eb dhe vet\u00ebm n\u00eb komunitetet nd\u00ebrkomb\u00ebtare) \u2013 kjo \u00ebsht\u00eb nj\u00eb rrjedh\u00eb q\u00eb transformohet nga e ftoht\u00eb n\u00eb t\u00eb ngroht\u00eb. Lind pyetja \u2013 ku t\u00eb p\u00ebrdoret? Do t\u00eb jap nj\u00eb shembull nga praktika.<\/p>\n<p><\/p>\n<p>Un\u00eb punoj me Angular. Ai p\u00ebrdor aktivisht rxjs. P\u00ebr t\u00eb marr\u00eb t\u00eb dh\u00ebna nga serveri, un\u00eb pres nj\u00eb rrjedh\u00eb t\u00eb ftoht\u00eb dhe k\u00ebt\u00eb rrjedh\u00eb e p\u00ebrdor n\u00eb shabllon p\u00ebrmes asyncPipe. N\u00ebse e p\u00ebrdor k\u00ebt\u00eb pip\u00eb disa her\u00eb, duke u kthyer te definicioni i rrjedh\u00ebs s\u00eb ftoht\u00eb, \u00e7do pip\u00eb do t\u00eb k\u00ebrkoj\u00eb t\u00eb dh\u00ebna nga serveri, q\u00eb \u00ebsht\u00eb, p\u00ebr ta th\u00ebn\u00eb but\u00eb, e \u00e7uditshme. Nd\u00ebrsa n\u00ebse e konvertoj rrjedh\u00ebn e ftoht\u00eb n\u00eb nj\u00eb t\u00eb ngroht\u00eb, k\u00ebrkesa do t\u00eb ndodh\u00eb vet\u00ebm nj\u00eb her\u00eb.<\/p>\n<p><\/p>\n<p>N\u00eb t\u00eb v\u00ebrtet\u00eb, kuptimi i llojeve t\u00eb rrjedhave \u00ebsht\u00eb mjaft i komplikuar p\u00ebr fillestar\u00ebt, por \u00ebsht\u00eb i r\u00ebnd\u00ebsish\u00ebm. <\/p>\n<p><\/p>\n<h3 id=\"operators\">Operators<\/h3>\n<p><\/p>\n<pre><code class=\"javascript\">return this.http.get(`${environment.apiUrl}\/${this.apiUrl}\/trade_companies`)\n    .pipe(\n        tap(({ data }: TradeCompanyList) =&gt; this.companies$$.next(cloneDeep(data))),\n        map(({ data }: TradeCompanyList) =&gt; data)\n    );<\/code><\/pre>\n<p><\/p>\n<p>Opertor\u00ebt na ofrojn\u00eb mund\u00ebsi t\u00eb zgjeruara p\u00ebr t\u00eb punuar me rrjedhat. Ata ndihmojn\u00eb n\u00eb kontrollin e ngjarjeve q\u00eb ndodhin n\u00eb Observable. Do t\u00eb shqyrtojm\u00eb disa nga m\u00eb t\u00eb njohurit, nd\u00ebrsa p\u00ebr m\u00eb shum\u00eb informacion rreth operator\u00ebve mund t\u00eb konsultoheni me lidhjet n\u00eb informacionin e dobish\u00ebm.<\/p>\n<p><\/p>\n<p><strong>Operators \u2014 of<\/strong><\/p>\n<p><\/p>\n<p>Le t\u00eb fillojm\u00eb me operatorin ndihm\u00ebs of. Ai krijon nj\u00eb Observable n\u00eb baz\u00eb t\u00eb nj\u00eb vler\u00eb t\u00eb thjesht\u00eb.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/68f382447e306392b025867a9a1e88e7.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operators \u2014 filter<\/strong><\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/24ac65fdb5ccc7f6301b3dfe49f1e804.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>Operatori i filtrimit filter, si\u00e7 mund t\u00eb kuptohet nga emri, filtrojn\u00eb sinjalin e rrjedh\u00ebs. N\u00ebse operatori kthen nj\u00eb v\u00ebrtet\u00ebsi, at\u00ebher\u00eb e kalon m\u00eb tej.<\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2014 merr<\/strong><\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/b3e7a2a2e03038d6fc250247ff4496a2.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>merr \u2014 Pranon vler\u00ebn e numrit t\u00eb emetimeve pas t\u00eb cilave mbyll rrjedh\u00ebn.<\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2014 debounceTime<\/strong><\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/add686e546a0b6169c38fb3b457da928.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>debounceTime \u2014 eliminon vlerat e emetuara q\u00eb bien brenda nj\u00eb periudhe kohe t\u00eb caktuar midis t\u00eb dh\u00ebnave t\u00eb daljes \u2014 pas kalimit t\u00eb intervalit kohor emeton vler\u00ebn e fundit.<\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const { Observable } = Rx;\nconst { debounceTime, take } = RxOperators;\n\nObservable.create((observer) =&gt; {\n  let i = 1;\n  observer.next(i++);\n  \/\/ Emeton vler\u00ebn \u00e7do 1000ms\n  setInterval(() =&gt; {\n    observer.next(i++)\n  }, 1000);\n\n \/\/ Emeton vler\u00ebn \u00e7do 1500ms\n  setInterval(() =&gt; {\n    observer.next(i++)\n  }, 1500);\n}).pipe(\n  debounceTime(700),  \/\/ Prit 700ms p\u00ebr vler\u00ebn para se ta\u51e6ie\n  take(3)\n);  <\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/dbb690d6fea6c43c1f0a2bdabea57934.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2014 takeWhile<\/strong><\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/120d9fe6ddf5a60ddffc8742989b27ff.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>Emeton vlera derisa takeWhile t\u00eb kthej\u00eb false, pas s\u00eb cil\u00ebs do t\u00eb \u00e7regjistrohet nga rrjedha.<\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const { Observable } = Rx;\nconst { debounceTime, takeWhile } = RxOperators;\n\nObservable.create((observer) =&gt; {\n  let i = 1;\n  observer.next(i++);\n  \/\/ Emeton vler\u00ebn \u00e7do 1000ms\n  setInterval(() =&gt; {\n    observer.next(i++)\n  }, 1000);\n}).pipe(\n  takeWhile( prodhues =&gt;  prodhues &lt; 5 )\n);  <\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/d2910d1bf9fab228acc9241fdbad3d4a.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2014 combineLatest<\/strong><\/p>\n<p><\/p>\n<p>Operatori i kombinuar combineLatest \u00ebsht\u00eb disi i ngjash\u00ebm me promise.all. Ai bashkon disa rrjedha n\u00eb nj\u00eb t\u00eb vet\u00ebm. Pasi \u00e7do rrjedh\u00eb t\u00eb emitoj\u00eb t\u00eb pakt\u00ebn nj\u00eb her\u00eb, ne marrim vlerat e fundit nga \u00e7do nj\u00ebri si nj\u00eb array. Pas \u00e7do emiti nga rrjedhat e kombinuara, ai do t\u00eb kthej\u00eb vlera t\u00eb reja.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/c39bc0a8a736ed30ad147055110bbf55.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const { combineLatest, Observable } = Rx;\nconst { take } = RxOperators;\n\nconst observer_1 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \/\/ Emiton nj\u00eb vler\u00eb \u00e7do 1000ms\n  setInterval(() =&gt; {\n    observer.next('a: ' + i++);\n  }, 1000);\n});\n\nconst observer_2 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \/\/ Emiton nj\u00eb vler\u00eb \u00e7do 750ms\n  setInterval(() =&gt; {\n    observer.next('b: ' + i++);\n  }, 750);\n});\n\ncombineLatest(observer_1, observer_2).pipe(take(5));<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/7fc35461f446987ef81302ff7c2ed5a8.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2014 zip<\/strong><\/p>\n<p><\/p>\n<p>Zip \u2014 pret nj\u00eb vler\u00eb nga secila rrjedh\u00eb dhe formon nj\u00eb array n\u00eb baz\u00eb t\u00eb k\u00ebtyre vlerave. N\u00ebse nuk vjen asnj\u00eb vler\u00eb nga ndonj\u00eb rrjedh\u00eb, grupi nuk do t\u00eb formohet.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/0be5ee0d2ec56bd2bc245b15d43d4cc1.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const { zip, Observable } = Rx;\nconst { take } = RxOperators;\n\nconst observer_1 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 1000ms\n  setInterval(() =&gt; {\n    observer.next('a: ' + i++);\n  }, 1000);\n});\n\nconst observer_2 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 750\n  setInterval(() =&gt; {\n    observer.next('b: ' + i++);\n  }, 750);\n});\n\nconst observer_3 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 500\n  setInterval(() =&gt; {\n    observer.next('c: ' + i++);\n  }, 500);\n});\n\nzip(observer_1, observer_2, observer_3).pipe(take(5));<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/e2606bf8ea5f8a660699ebe896a27d80.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operators \u2014 forkJoin<\/strong><\/p>\n<p><\/p>\n<p>forkJoin gjithashtu bashkon rrjedhat, por ai e l\u00ebshon vler\u00ebn vet\u00ebm kur t\u00eb gjitha rrjedhat t\u00eb p\u00ebrfundojn\u00eb (complete).<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/6c430d7eeafbc8a7c1c228ddfe0e44b5.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const { forkJoin, Observable } = Rx;\nconst { take } = RxOperators;\n\nconst observer_1 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 1000ms\n  setInterval(() =&gt; {\n    observer.next('a: ' + i++);\n  }, 1000);\n}).pipe(take(3));\n\nconst observer_2 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 750\n  setInterval(() =&gt; {\n    observer.next('b: ' + i++);\n  }, 750);\n}).pipe(take(5));\n\nconst observer_3 = Observable.create((observer) =&gt; {\n  let i = 1;\n  \\\/\\\/ Emitted value every 500\n  setInterval(() =&gt; {\n    observer.next('c: ' + i++);\n  }, 500);\n}).pipe(take(4));\n\nforkJoin(observer_1, observer_2, observer_3);<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/df110efc7ece46fc1d8da2d7693f75bb.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operators \u2014 map<\/strong><\/p>\n<p><\/p>\n<p>Operatori i transformimit map e ndryshon vler\u00ebn e emetimit n\u00eb nj\u00eb t\u00eb re. <\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/2196ff9f82dd7aaeb00ab76475176d32.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<pre><code class=\"javascript\">const {  Observable } = Rx;\nconst { take, map } = RxOperators;\n\nObservable.create((observer) =&gt; {\n  let i = 1;\n  \/\/ \u00c7lirojn\u00eb vler\u00ebn \u00e7do 1000ms\n  setInterval(() =&gt; {\n    observer.next(i++);\n  }, 1000);\n}).pipe(\n  map(x =&gt; x * 10),\n  take(3)\n);\n<\/code><\/pre>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/4e4ff3e2eb4acf69f16559c711a2e666.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p><strong>Operator\u00ebt \u2013 share, tap<\/strong><\/p>\n<p><\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 tap\u00a0&#8212; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c side \u044d\u0444\u0444\u0435\u043a\u0442\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p><\/p>\n<p>Operatori utilitar share \u00ebsht\u00eb n\u00eb gjendje t\u00eb b\u00ebj\u00eb nga nj\u00eb rrjedh\u00eb t\u00eb ftoht\u00eb nj\u00eb rrjedh\u00eb t\u00eb ngroht\u00eb. <\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Programimi asinkron n\u00eb JavaScript. (Callback, Promise, RxJs)\" src=\"\/wp-content\/uploads\/2019\/08\/c46e96420ed78d197ceef829ff74c82d.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<p>Me operator\u00ebt p\u00ebrfunduam. Tani do t\u00eb kalojm\u00eb te Subject.<\/p>\n<p>\n<b class=\"spoiler_title\">T\u00eb mendojm\u00eb n\u00eb z\u00eb<\/b><\/p>\n<p>Dhe k\u00ebtu shkova t\u00eb pi \u00e7aj. M\u00eb lodh\u00ebn k\u00ebto shembuj \ud83d\ude00<\/p>\n<p><\/p>\n<h2 id=\"semeystvo-subject-ov\">Familja e subject-\u00ebve<\/h2>\n<p><\/p>\n<p>Familja e subject-\u00ebve \u00ebsht\u00eb nj\u00eb shembull i shk\u00eblqyer i rrjedhave t\u00eb ngrohta. K\u00ebto klasa jan\u00eb nj\u00eb hibrid, q\u00eb veprojn\u00eb nj\u00ebherazi si observable dhe observer. Duke qen\u00eb se subject \u00ebsht\u00eb nj\u00eb rrjedh\u00eb e ngroht\u00eb, \u00ebsht\u00eb e nevojshme t\u00eb mbahen n\u00eb mend se duhet t\u00eb shk\u00ebputeni. N\u00eb lidhje me metodat kryesore, ato jan\u00eb:<\/p>\n<p><\/p>\n<ul>\n<li>next \u2013 d\u00ebrgimi i t\u00eb dh\u00ebnave t\u00eb reja n\u00eb rrjedh\u00eb<\/li>\n<li>error \u2013 gabim dhe p\u00ebrfundimi i rrjedh\u00ebs<\/li>\n<li>complete \u2013 p\u00ebrfundimi i rrjedh\u00ebs<\/li>\n<li>subscribe \u2013 abonohem n\u00eb rrjedh\u00eb<\/li>\n<li>unsubscribe \u2013 shk\u00ebputem nga rrjedha<\/li>\n<li>asObservable \u2013 e transformojm\u00eb n\u00eb nj\u00eb v\u00ebzhgues<\/li>\n<li>toPromise \u2013 e transformon n\u00eb nj\u00eb premtim<\/li>\n<\/ul>\n<p><\/p>\n<p>Dallohet 4-5 lloje subject-\u00ebsh. <\/p>\n<p>\n<b class=\"spoiler_title\">T\u00eb mendojm\u00eb n\u00eb z\u00eb<\/b><\/p>\n<p>N\u00eb stream thash\u00eb 4, por doli se ata kan\u00eb shtuar nj\u00eb tjet\u00ebr. Si\u00e7 thon\u00eb, jeton dhe m\u00ebso!<\/p>\n<p><\/p>\n<p>Subject i thjesht\u00eb <code>new Subject()<\/code>\u2013 lloji m\u00eb i thjesht\u00eb i subject-eve. Krijohet pa parametra. Transmeton vlerat q\u00eb vijn\u00eb vet\u00ebm pas abonimit.<\/p>\n<p><\/p>\n<p>BehaviorSubject <code>new BehaviorSubject( defaultData )<\/code> \u2013 sipas mendimit tim, lloji m\u00eb i zakonsh\u00ebm i subject-eve. Merr nj\u00eb vler\u00eb fillestare. Gjithmon\u00eb ruan t\u00eb dh\u00ebnat e l\u00ebshimit t\u00eb fundit, t\u00eb cilat i transmeton gjat\u00eb abonimit. Ky klas ka gjithashtu nj\u00eb metod\u00eb t\u00eb dobishme value, e cila kthen vler\u00ebn aktuale t\u00eb rrjedh\u00ebs.<\/p>\n<p><\/p>\n<p>ReplaySubject <code>new ReplaySubject(bufferSize?: number, windowTime?: number)<\/code> \u2014 Mund t\u00eb marr\u00eb si argument t\u00eb par\u00eb opsional madh\u00ebsin\u00eb e tamponit t\u00eb vlerave q\u00eb do t\u00eb mbaj\u00eb, dhe si t\u00eb dyt\u00eb koh\u00ebn gjat\u00eb s\u00eb cil\u00ebs na nevojiten ndryshimet.<\/p>\n<p><\/p>\n<p>AsyncSubject <code>new AsyncSubject()<\/code> \u2014 gjat\u00eb abonimit nuk ndodh asgj\u00eb, dhe vlera do t\u00eb kthehet vet\u00ebm kur t\u00eb p\u00ebrfundoj\u00eb. Do t\u00eb kthehet vet\u00ebm vlera e fundit e rrjedh\u00ebs.<\/p>\n<p><\/p>\n<p>WebSocketSubject <code>new WebSocketSubject(urlConfigOrSource: string | WebSocketSubjectConfig | Observable, destination?: Observer)<\/code> \u2014 Dokumentacioni nuk thot\u00eb asgj\u00eb p\u00ebr t\u00eb, dhe un\u00eb e shoh p\u00ebr her\u00eb t\u00eb par\u00eb. Kush e di se \u00e7far\u00eb b\u00ebn, ju lutem shkruani, do ta plot\u00ebsojm\u00eb.<\/p>\n<p><\/p>\n<p>Ah, k\u00ebshtu q\u00eb ne kemi shqyrtuar gjith\u00e7ka q\u00eb doja t\u00eb ndaja sot. Shpresoj q\u00eb kjo informacion t\u00eb ket\u00eb qen\u00eb e dobishme. Mund t\u00eb shqyrtoni list\u00ebn e literatur\u00ebs n\u00eb seksionin e informacionit t\u00eb dobish\u00ebm.<\/p>\n<p><\/p>\n<h2 id=\"poleznaya-informaciya\">Informacion i dobish\u00ebm<\/h2>\n<p><\/p>\n<ul>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/vk.com\/frontend_practice?w=wall-182297870_931\">https:\/\/vk.com\/frontend_practice?w=wall-182297870_931<\/a><\/noindex> \u2014 lidhje me stream-in<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/337042\/\">https:\/\/habr.com\/ru\/company\/ruvds\/blog\/337042\/<\/a><\/noindex> \u2014 Si funksionon JS: nj\u00eb p\u00ebrmbledhje e motorit, mekanizmave t\u00eb ekzekutimit, stack-ut t\u00eb thirrjeve<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/340508\/\">https:\/\/habr.com\/ru\/company\/ruvds\/blog\/340508<\/a><\/noindex> \u2014 Si funksionon JS: cikli i ngjarjeve, asinkronia dhe pes\u00eb m\u00ebnyra p\u00ebr t\u00eb p\u00ebrmir\u00ebsuar kodin me async \/ await<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"http:\/\/vanilla-js.blogspot.com\/2014\/09\/event-loop-javasript.html\">http:\/\/vanilla-js.blogspot.com\/2014\/09\/event-loop-javasript.html<\/a><\/noindex> \u2014 Si funksionon Event Loop n\u00eb JavaScript<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/tproger.ru\/translations\/asynchronous-javascript\/\">https:\/\/tproger.ru\/translations\/asynchronous-javascript\/<\/a><\/noindex> \u2014 Evolucioni i JavaScript-it asinkron<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/ruvds\/blog\/341880\/\">https:\/\/habr.com\/ru\/company\/ruvds\/blog\/341880\/<\/a><\/noindex> \u2014 \u00c7far\u00eb \u00ebsht\u00eb RxJS dhe p\u00ebrse \u00ebsht\u00eb e r\u00ebnd\u00ebsishme t\u00eb dihet p\u00ebr t\u00eb<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/medium.com\/ngx\/practical-use-rxjs-81aaab57045c\">https:\/\/medium.com\/ngx\/practical-use-rxjs-81aaab57045c<\/a><\/noindex> \u2014 P\u00ebrdorimi praktike i RxJS<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/coursetro.com\/posts\/code\/148\/RxJS-Observables-Tutorial---Creating-&amp;-Subscribing-to-Observables\">https:\/\/coursetro.com\/posts\/code\/148\/RxJS-Observables-Tutorial&#8212;Creating-&amp;-Subscribing-to-Observables<\/a><\/noindex> \u2014 Tutoriali i RxJS Observables \u2014 Krijimi dhe N\u00ebnshkrimi n\u00eb Observables<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/slides.com\/zenabsaleem\/rxjs-hot-cold-observables#\/\">https:\/\/slides.com\/zenabsaleem\/rxjs-hot-cold-observables#\/<\/a><\/noindex> \u2014 RXJS: Observables t\u00eb Nxehta dhe t\u00eb Ftohta<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/clck.ru\/FiPgB\">https:\/\/clck.ru\/FiPgB<\/a><\/noindex> \u2014 Klasa, funksione p\u00ebr krijimin e Observable. Operator\u00ebt.<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/www.learnrxjs.io\/operators\/\">https:\/\/www.learnrxjs.io\/operators\/<\/a><\/noindex> \u2014 Operator\u00ebt e RxJS sipas shembujve<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/rxjs.dev\/api\">https:\/\/rxjs.dev\/api<\/a><\/noindex> \u2014 Lista e API-ve<\/li>\n<li><noindex><a rel=\"nofollow\" href=\"https:\/\/clck.ru\/FkS8Y\">https:\/\/clck.ru\/FkS8Y<\/a><\/noindex> \u2014 Llojet e Subject dhe Orare n\u00eb RxJS<\/li>\n<\/ul>\n<p>Burimi: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/462355\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041e\u043c\u0435\u043b\u044c\u043d\u0438\u0446\u043a\u0438\u0439 \u0421\u0435\u0440\u0433\u0435\u0439. \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u0432\u0435\u043b \u0441\u0442\u0440\u0438\u043c \u043f\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0433\u0434\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 JavaScript. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0437\u0430\u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0432\u043e\u0434\u043d\u0443\u044e. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439: \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c? \u0421\u0442\u0435\u043a \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":27545,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[702],"tags":[],"class_list":["post-36774","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-novosti-interneta"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041e\u043c\u0435\u043b\u044c\u043d\u0438\u0446\u043a\u0438\u0439 \u0421\u0435\u0440\u0433\u0435\u0439. \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u0432\u0435\u043b \u0441\u0442\u0440\u0438\u043c \u043f\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0433\u0434\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 JavaScript. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0437\u0430\u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0432\u043e\u0434\u043d\u0443\u044e. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439: \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c? \u0421\u0442\u0435\u043a \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/sq\/blog\/novosti-interneta\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"sq_AL\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 JavaScript. ( Callback, Promise, RxJs ) | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041e\u043c\u0435\u043b\u044c\u043d\u0438\u0446\u043a\u0438\u0439 \u0421\u0435\u0440\u0433\u0435\u0439. \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u0432\u0435\u043b \u0441\u0442\u0440\u0438\u043c \u043f\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0433\u0434\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 JavaScript. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0437\u0430\u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0432\u043e\u0434\u043d\u0443\u044e. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439: \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c? \u0421\u0442\u0435\u043a \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/sq\/blog\/novosti-interneta\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T19:13:44+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T19:13:44+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Programimi asinkron n\u00eb JavaScript. ( Callback, Promise, RxJs ) | ProHoster","description":"P\u00ebrsh\u00ebndetje t\u00eb gjith\u00ebve. Jam Omelnytskyi Serhii. Pak koh\u00eb m\u00eb par\u00eb mbajta nj\u00eb transmetim n\u00eb lidhje me programimin reaktiv, ku flas p\u00ebr asinkronizimin n\u00eb JavaScript. Sot do t\u00eb doja t\u00eb p\u00ebrmbledh materialin e k\u00ebtij transmetimi. Por para se t\u00eb fillojm\u00eb me materialin kryesor, na nevojitet nj\u00eb hyrje. Pra, le t\u00eb fillojm\u00eb me p\u00ebrkufizimet: \u00e7far\u00eb \u00ebsht\u00eb nj\u00eb stek dhe nj\u00eb radh\u00eb? Steku \u00ebsht\u00eb nj\u00eb koleksion, elementet e s\u00eb cilit","canonical_url":"https:\/\/prohoster.info\/sq\/blog\/novosti-interneta\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"sq_AL","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 JavaScript. ( Callback, Promise, RxJs ) | ProHoster","og:description":"\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041e\u043c\u0435\u043b\u044c\u043d\u0438\u0446\u043a\u0438\u0439 \u0421\u0435\u0440\u0433\u0435\u0439. \u041d\u0435 \u0442\u0430\u043a \u0434\u0430\u0432\u043d\u043e \u044f \u0432\u0435\u043b \u0441\u0442\u0440\u0438\u043c \u043f\u043e \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e, \u0433\u0434\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043f\u0440\u043e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 JavaScript. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0437\u0430\u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u041d\u043e \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0432\u043e\u0434\u043d\u0443\u044e. \u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439: \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0435\u043a \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c? \u0421\u0442\u0435\u043a \u2014 \u044d\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u043e\u0439","og:url":"https:\/\/prohoster.info\/sq\/blog\/novosti-interneta\/asinhronnoe-programmirovanie-v-javascript-callback-promise-rxjs","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T19:13:44+00:00","article:modified_time":"2019-10-31T19:13:44+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"36774","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-22 04:48:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 01:39:22","updated":"2026-01-22 04:48:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/36774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/comments?post=36774"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/posts\/36774\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/media\/27545"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/media?parent=36774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/categories?post=36774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/sq\/wp-json\/wp\/v2\/tags?post=36774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}