<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Promises._Async-Await</id>
	<title>Promises. Async-Await - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=Promises._Async-Await"/>
	<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;action=history"/>
	<updated>2026-08-30T06:30:33Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298571&amp;oldid=prev</id>
		<title>Joan: /* Tasques a realitzar */</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298571&amp;oldid=prev"/>
		<updated>2022-02-24T18:11:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Tasques a realitzar&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 18:11, 24 feb 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l98&quot; &gt;Línia 98:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 98:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fetchingData2();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fetchingData2();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Tasques a realitzar=&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Tasques a realitzar &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(entrega de classe)&lt;/ins&gt;=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Visionar els dos vídeos que es proposen, i que s'han explicat a classe. El primer vídeo és un repàs de les funcions fletxa. El segon vídeo explica les ''Promises'', i com fer funcions async/await per gestionar les funcions asíncrones.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Visionar els dos vídeos que es proposen, i que s'han explicat a classe. El primer vídeo és un repàs de les funcions fletxa. El segon vídeo explica les ''Promises'', i com fer funcions async/await per gestionar les funcions asíncrones.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298570&amp;oldid=prev</id>
		<title>Joan a 18:11, 24 feb 2022</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298570&amp;oldid=prev"/>
		<updated>2022-02-24T18:11:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 18:11, 24 feb 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l98&quot; &gt;Línia 98:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 98:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fetchingData2();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fetchingData2();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;=Tasques a realitzar=&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Visionar els dos vídeos que es proposen, i que s'han explicat a classe. El primer vídeo és un repàs de les funcions fletxa. El segon vídeo explica les ''Promises'', i com fer funcions async/await per gestionar les funcions asíncrones.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Entregaràs el ''script_funcions_arrow.js'' i el ''script_promises.js'', demostrant que els has executat en la teva màquina i que has fet canvis en el codi. Obligatòriament has de fer els següents canvis:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*del primer script, canvia el contingut de la funció (que no sigui elevar al quadrat un número).&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*del segon script, canvia el contingut de l'array de ''dades''.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Autor}}, febrer 2022&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Autor}}, febrer 2022&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298550&amp;oldid=prev</id>
		<title>Joan: Es crea la pàgina amb «__TOC__ =Funcions de fletxa= *https://www.youtube.com/watch?v=aIKL5tQP25Y &lt;pre&gt; //https://www.youtube.com/watch?v=aIKL5tQP25Y /* cd /home/joan/M06_WEC_2122/UF4/promise...».</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=Promises._Async-Await&amp;diff=298550&amp;oldid=prev"/>
		<updated>2022-02-22T15:59:13Z</updated>

		<summary type="html">&lt;p&gt;Es crea la pàgina amb «__TOC__ =Funcions de fletxa= *https://www.youtube.com/watch?v=aIKL5tQP25Y &amp;lt;pre&amp;gt; //https://www.youtube.com/watch?v=aIKL5tQP25Y /* cd /home/joan/M06_WEC_2122/UF4/promise...».&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
=Funcions de fletxa=&lt;br /&gt;
*https://www.youtube.com/watch?v=aIKL5tQP25Y&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//https://www.youtube.com/watch?v=aIKL5tQP25Y&lt;br /&gt;
/*&lt;br /&gt;
cd /home/joan/M06_WEC_2122/UF4/promises_async_await/&lt;br /&gt;
node arrow_functions.js&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
function fsquare(x) {&lt;br /&gt;
	return x*x;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const fsquare2 = function(x) { //funció anònima&lt;br /&gt;
	return x*x;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const squareArrow = (x) =&amp;gt; x*x;&lt;br /&gt;
const squareArrow2 = (x) =&amp;gt; { return x*x};&lt;br /&gt;
&lt;br /&gt;
console.log(fsquare(2));&lt;br /&gt;
console.log(fsquare2(3));&lt;br /&gt;
console.log(squareArrow(4));&lt;br /&gt;
console.log(squareArrow2(5));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=Promeses. Funcions asíncrones amb async/awayt=&lt;br /&gt;
*https://www.youtube.com/watch?v=rKK1q7nFt7M&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//https://www.youtube.com/watch?v=rKK1q7nFt7M&lt;br /&gt;
/*&lt;br /&gt;
cd /home/joan/M06_WEC_2122/UF4/promises_async_await/&lt;br /&gt;
node promises_async_await.js&lt;br /&gt;
&lt;br /&gt;
NOTA: exemple d'on utilitzem async/await i bases de dades: parcellacio_v5.js (La Palma)&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
const dades = [&lt;br /&gt;
	{ id : 1, title : 'Iron Man', year : 2008 },&lt;br /&gt;
	{ id : 2, title : 'Spiderman', year : 2017 },&lt;br /&gt;
	{ id : 3, title : 'Avengers', year : 2019 }&lt;br /&gt;
]&lt;br /&gt;
&lt;br /&gt;
const dades2 = []&lt;br /&gt;
&lt;br /&gt;
//funció sincrona&lt;br /&gt;
const getDades = () =&amp;gt; { return dades; }&lt;br /&gt;
&lt;br /&gt;
//funció asíncrona (simulem un delay)&lt;br /&gt;
const getDades2 = () =&amp;gt; {&lt;br /&gt;
	setTimeOut = (() =&amp;gt; {dades},1500);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const getDades3 = () =&amp;gt; {&lt;br /&gt;
	return new Promise((resolve, reject) =&amp;gt; {&lt;br /&gt;
		setTimeout(() =&amp;gt; {resolve(dades);},1500);&lt;br /&gt;
	})&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
const getDades4 = () =&amp;gt; {&lt;br /&gt;
	return new Promise((resolve, reject) =&amp;gt; {&lt;br /&gt;
		setTimeout(() =&amp;gt; {resolve(dades);},1500);&lt;br /&gt;
	})&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//el mateix però amb control d'errors&lt;br /&gt;
const getDades5 = () =&amp;gt; {&lt;br /&gt;
	return new Promise((resolve, reject) =&amp;gt; {&lt;br /&gt;
		if (dades2.length===0) reject(new Error('no existeixen dades'));	&lt;br /&gt;
		setTimeout(() =&amp;gt; {resolve(dades);},1500);&lt;br /&gt;
	})&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
async function fetchingData() {&lt;br /&gt;
	const dadesFetched = await getDades4();&lt;br /&gt;
	console.log(dadesFetched);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
async function fetchingData2() {&lt;br /&gt;
	try {&lt;br /&gt;
		const dadesFetched = await getDades5();&lt;br /&gt;
		console.log(dadesFetched);&lt;br /&gt;
	} catch(err) {&lt;br /&gt;
		console.log(err.message);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//la manera async-wait és la mateixa idea que les promeses (crida asíncrona), però la manera d'escriure-ho és més síncrona, més seqüencial&lt;br /&gt;
console.log(getDades());&lt;br /&gt;
console.log(getDades2()); //retorna undefined perquè el console.log() s'imprmeix immediatament, el console.log() no espera els 1500ms&lt;br /&gt;
console.log(getDades3()); //retorna Promise { &amp;lt;pending&amp;gt; } (així no es fa, falta alguna cosa encara)&lt;br /&gt;
getDades4()&lt;br /&gt;
	.then((dades)=&amp;gt;{return console.log(dades)}) //ara sí que espera el temps i imprimeix les dades&lt;br /&gt;
	.catch(err =&amp;gt; console.log(console.log(err.message)));&lt;br /&gt;
&lt;br /&gt;
fetchingData();&lt;br /&gt;
fetchingData2();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{{Autor}}, febrer 2022&lt;/div&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
</feed>