<snapdata remixID="11929640"><project name="Promises library" app="Snap! 7, https://snap.berkeley.edu" version="2"><notes></notes><thumbnail>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAB4CAYAAAB1ovlvAAACqElEQVR4Xu3XMY7aUABF0e99QA/LAYkN0bAgEKuBjUBBRqSYYmaSKIWvZB3Xlp58/xHG0+vjGi4FogITgFF5s+8CAIKQFgAwzW8cQAbSAgCm+Y0DyEBaAMA0v3EAGUgLAJjmNw4gA2kBANP8xgFkIC0AYJrfOIAMpAUATPMbB5CBtACAaX7jADKQFgAwzW8cQAbSAgCm+Y0DyEBaAMA0v3EAGUgLAJjmNw4gA2kBANP8xgFkIC0AYJrfOIAMpAUATPMbB5CBtACAaX7jADKQFgAwzW8cQAbSAgCm+Y0DyEBaAMA0v3EAGUgLAJjmNw4gA2kBANP8xgFkIC0AYJrfOIAMpAUATPMbB5CBtACAaX7jADKQFgAwzW8cQAbSAgCm+Y0DyEBaAMA0v3EAGUgLAPhD/u12O47H4zgcDukBLX0cwD+c8H6/H6/X633H7XYb1+t1rNfrpZuY9fkA/Evu3W735Y5pmsbz+Rzn83nWw1riGID/CfDxeIzL5bJEE7M+E4D/+Aq+3+/vV/BqtZr1gJY+BuAPJ7zZbMbpdBrfvYKXjmLO5wNwztq2vv6f/vjK+/2Z51IgKOAXMIhu8rMAgDSkBQBM8xsHkIG0AIBpfuMAMpAWADDNbxxABtICAKb5jQPIQFoAwDS/cQAZSAsAmOY3DiADaQEA0/zGAWQgLQBgmt84gAykBQBM8xsHkIG0AIBpfuMAMpAWADDNbxxABtICAKb5jQPIQFoAwDS/cQAZSAsAmOY3DiADaQEA0/zGAWQgLQBgmt84gAykBQBM8xsHkIG0AIBpfuMAMpAWADDNbxxABtICAKb5jQPIQFoAwDS/cQAZSAsAmOY3DiADaQEA0/zGAWQgLQBgmt84gAykBQBM8xsHkIG0AIBpfuMAMpAWADDNb/wXK14Ct+2fpIIAAAAASUVORK5CYII=</thumbnail><scenes select="1"><scene name="Promises library"><notes></notes><palette><category name="Promises" color="255,125,87,1"/></palette><hidden></hidden><headers></headers><code></code><blocks><block-definition s="error %&apos;msg&apos;" type="command" category="control"><comment x="0" y="0" w="268.6666666666667" collapsed="false">Throw an error.&#xD;&#xD;Makes a red halo appear around the script that runs it,&#xD;with the input text shown in a speech balloon next to&#xD;the script, just like any Snap! error.&#xD;&#xD;This is useful to put in the second script of SAFELY TRY&#xD;after some other instructions to undo the partial work of&#xD;the first script.</comment><header></header><code></code><translations>pt:lança o erro _&#xD;</translations><inputs><input type="%txt"></input></inputs><script><block s="doApplyExtension"><l>err_error(msg)</l><list><block var="msg"/></list></block></script></block-definition><block-definition s="multiline %&apos;text&apos;" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%mlt"></input></inputs><script><block s="doReport"><block var="text"/></block></script></block-definition><block-definition s="ignore %&apos;x&apos;" type="command" category="control"><comment x="0" y="0" w="206.66666666666666" collapsed="false">This block does nothing.&#xD;Use it when you are calling a reporter&#xD;for its side effect and don&apos;t care about&#xD;its return value.</comment><header></header><code></code><translations>de:ignoriere _&#xD;ca:ignora _&#xD;es:ignorar _&#xD;fr:ignore _&#xD;pt:ignora _&#xD;</translations><inputs><input type="%s"></input></inputs></block-definition><block-definition s="ignore %&apos;x&apos; and report %&apos;val&apos;" type="reporter" category="control"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%s"></input></inputs><script><block s="doReport"><block var="val"/></block></script></block-definition><block-definition s="%&apos;x&apos;" type="reporter" category="operators"><comment x="0" y="0" w="105.33333333333333" collapsed="false">The identity function reports its input.</comment><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block var="x"/></block></script></block-definition><block-definition s="try %&apos;this&apos; catch %&apos;error&apos; %&apos;that&apos;" type="reporter" category="control"><comment x="0" y="0" w="316.6666666666667" collapsed="false">Catch errors in a reporter.&#xD;&#xD;Evaluates its first input.  If that expression successfully reports a value, this block reports that value.  If the expression causes a Snap! error,&#xD;then the final input slot is evaluated with the text of what would have&#xD;been the error message in variable ERROR.  SAFELY TRY then reports the value of that final expression.&#xD;&#xD;Sometimes you&apos;ll want to throw an error in the final expression.  You&#xD;can put an ERROR block inside a CALL block to do that.</comment><header></header><code></code><translations>ca:prova de forma segura reportant _ i si _ reportant _&#xD;</translations><inputs><input type="%anyUE"></input><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doDeclareVariables"><list><l>value</l></list></block><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSetVar"><l>value</l><block s="evaluate"><block var="this"/><list></list></block></block></script><l>err</l><script><block s="doSetVar"><l>error</l><block var="err"/></block><block s="doSetVar"><l>value</l><block s="evaluate"><block var="that"/><list></list></block></block></script></custom-block><block s="doReport"><block var="value"/></block></script></block-definition><block-definition s="safely try %&apos;action&apos; then if %&apos;error&apos; %&apos;handler&apos;" type="command" category="control"><comment x="0" y="0" w="276" collapsed="false">Catch errors.&#xD;&#xD;Runs the first script.  If it succeeds, nothing else happens.&#xD;But if it has an error (something that would otherwise result&#xD;in a red halo around the block), then the second script is run,&#xD;with the text of the error message that would have been shown in the variable ERROR.</comment><header></header><code></code><translations>pt:tenta executar _ e, em caso de erro _ , executa _&#xD;ca:prova de forma segura _ i si _ _&#xD;</translations><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doApplyExtension"><l>err_try(cmd, catch, err)</l><list><block var="action"/><block var="handler"/><block var="error"/></list></block><block s="doApplyExtension"><l>err_reset</l><list></list></block></script></block-definition><block-definition s="promise %&apos;ring&apos; %&apos;inputs&apos;" type="reporter" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%repRing"></input><input type="%inputs"></input></inputs><script><block s="doDeclareVariables"><list><l>done</l><l>success</l><l>reported</l><l>result</l></list></block><block s="doSetVar"><l>done</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><block s="doSetVar"><l>success</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><block s="doSetVar"><l>reported</l><block s="reportBoolean"><l><bool>true</bool></l></block></block><block s="fork"><block s="reifyScript"><script><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSetVar"><l>result</l><block s="evaluate"><block s="reifyReporter"><script><block s="doRun"><block var="ring"/><block var="inputs"/></block><block s="doSetVar"><l>reported</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><block s="doReport"><l></l></block></script><list></list></block><list></list></block></block><block s="doSetVar"><l>success</l><block s="reportBoolean"><l><bool>true</bool></l></block></block></script><l>error</l><script><block s="doSetVar"><l>result</l><block var="error"/></block></script></custom-block><block s="doSetVar"><l>done</l><block s="reportBoolean"><l><bool>true</bool></l></block></block></script><list></list></block><list></list></block><block s="doReport"><block s="reifyScript"><script><block s="doWaitUntil"><block var="done"/></block><block s="doIfElse"><block var="success"/><script><block s="doIf"><block var="reported"/><script><block s="doReport"><block var="result"/></block></script></block></script><script><custom-block s="error %txt"><block var="result"/></custom-block></script></block></script><list></list></block></block></script></block-definition><block-definition s="await %&apos;promise&apos;" type="reporter" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%n" readonly="true"></input></inputs><script><block s="doIfElse"><block s="reportIsA"><block var="promise"/><l><option>list</option></l></block><script><block s="doReport"><block s="reportMap"><block s="reifyReporter"><autolambda><custom-block s="await %n"><l></l></custom-block></autolambda><list></list></block><block var="promise"/></block></block></script><script><block s="doReport"><block s="evaluate"><block var="promise"/><list></list></block></block></script></block></script></block-definition><block-definition s="await %&apos;promise&apos;" type="command" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"></input></inputs><script><block s="doIfElse"><block s="reportIsA"><block var="promise"/><l><option>list</option></l></block><script><block s="doForEach"><l>item</l><block var="promise"/><script><custom-block s="await %s"><block var="item"/></custom-block></script></block></script><script><block s="doRun"><block var="promise"/><list></list></block></script></block></script></block-definition><block-definition s="%&apos;promise&apos; succeeded?" type="predicate" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"></input></inputs><script><block s="doReport"><block s="reportAttributeOf"><custom-block s="%s"><l>success</l></custom-block><block var="promise"/></block></block></script></block-definition><block-definition s="%&apos;promise&apos; then %&apos;ring&apos;" type="reporter" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%n" readonly="true"></input><input type="%repRing"></input></inputs><script><block s="doReport"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doRun"><block var="ring"/><list><block s="evaluate"><block var="promise"/><list></list></block></list></block></script><list></list></block><list></list></custom-block></block></script></block-definition><block-definition s="%&apos;promise&apos; catch %&apos;ring&apos;" type="reporter" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"></input><input type="%repRing" readonly="true"></input></inputs><script><block s="doReport"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doRun"><block var="promise"/><list></list></block></script><l>error</l><script><block s="doRun"><block var="ring"/><block var="error"/></block></script></custom-block></script><list></list></block><list></list></custom-block></block></script></block-definition><block-definition s="%&apos;promise&apos; is complete?" type="predicate" category="Promises"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"></input></inputs><script><block s="doReport"><block s="reportAttributeOf"><custom-block s="%s"><l>done</l></custom-block><block var="promise"/></block></block></script></block-definition><block-definition s="empty" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs></inputs><script><block s="doReport"><l></l></block></script></block-definition></blocks><stage name="Stage" width="480" height="360" costume="0" color="255,255,255,1" tempo="60" threadsafe="false" penlog="false" volume="100" pan="0" lines="round" ternary="false" hyperops="true" codify="false" inheritance="true" sublistIDs="false" id="289"><pentrails>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAFoCAYAAACPNyggAAAOhUlEQVR4Xu3VwQkAAAjEMN1/abewn7jAQRC64wgQIECAAIF3gX1fNEiAAAECBAiMAHsCAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQICLAfIECAAAECgYAAB+gmCRAgQICAAPsBAgQIECAQCAhwgG6SAAECBAgIsB8gQIAAAQKBgAAH6CYJECBAgIAA+wECBAgQIBAICHCAbpIAAQIECAiwHyBAgAABAoGAAAfoJgkQIECAgAD7AQIECBAgEAgIcIBukgABAgQIHLFxAWmhEwHPAAAAAElFTkSuQmCC</pentrails><costumes><list struct="atomic" id="290"></list></costumes><sounds><list struct="atomic" id="291"></list></sounds><variables></variables><blocks></blocks><scripts></scripts><sprites select="1"><sprite name="Sprite" idx="1" x="0" y="0" heading="90" scale="1" volume="100" pan="0" rotation="1" draggable="true" costume="0" color="80,80,80,1" pen="tip" id="296"><costumes><list struct="atomic" id="297"></list></costumes><sounds><list struct="atomic" id="298"></list></sounds><blocks></blocks><variables></variables><scripts><comment x="20" y="20" w="353" collapsed="false">PURPOSE:&#xD;&#xD;launch scripts and get the results later</comment><comment x="20" y="98" w="457" collapsed="false">THINGS THAT CAN&apos;T BE DONE YET:&#xD;&#xD;stop a process directly (you can only manage this yourself by starting the process in a particular sprite, and stopping all scripts in that sprite)&#xD;merging promise and track into one block&#xD;detect if a process won&apos;t complete (sorry, the halting problem isn&apos;t solvable)</comment><comment x="20" y="212" w="341" collapsed="false">INTENTIONALLY LEFT OUT:&#xD;&#xD;many things demonstrated in the scripts here (readable enough)</comment><script x="20" y="290"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doSayFor"><l>Hello!</l><l>2</l></block><block s="doReport"><l>3</l></block></script><list></list></block><list></list><comment w="243" collapsed="false">start a reporter, and keep track of it&#xD;if it doesn&apos;t report, it won&apos;t report on await</comment></custom-block></script><script x="20" y="359"><custom-block s="await %n"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>1</l></block><block s="doReport"><l>Hello!</l></block></script><list></list></block><list></list></custom-block><comment w="277.5" collapsed="false">wait for the promise to complete, and give the result&#xD;&#xD;if the promise has an error, await will give the same error&#xD;if the promise doesn&apos;t report, this will error</comment></custom-block></script><script x="20" y="452"><custom-block s="await %s"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>1</l></block></script><list></list></block><list></list></custom-block><comment w="330" collapsed="false">wait for the promise to complete&#xD;&#xD;if the promise has an error, await will give the same error&#xD;reports propogate</comment></custom-block></script><script x="20" y="545"><block s="doDeclareVariables"><list><l>promise</l></list></block><block s="doSetVar"><l>promise</l><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>2</l></block></script><list></list></block><list></list></custom-block></block><block s="bubble"><l>Loading...</l></block><block s="doUntil"><custom-block s="%s is complete?"><block var="promise"/><comment w="312" collapsed="false">says if the command is complete, regardless of it succeeded or failed</comment></custom-block><script><block s="turn"><l>5</l></block></script></block><custom-block s="await %s"><block var="promise"/><comment w="272" collapsed="false">the command is done, but this will give an error if there is one</comment></custom-block><block s="setHeading"><l>90</l></block><block s="bubble"><l></l></block></script><script x="20" y="769.5"><custom-block s="%s succeeded?"><l></l><comment w="170" collapsed="false">true only if completed AND no error</comment></custom-block></script><script x="20" y="826.5"><custom-block s="await %n"><block s="reportNewList"><list><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>1</l></block><block s="doReport"><l>one</l></block></script><list></list></block><list></list></custom-block><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>2</l></block><block s="doReport"><l>two</l></block></script><list></list></block><list></list></custom-block></list></block></custom-block></script><script x="20" y="901.5"><custom-block s="%n then %repRing"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>.5</l></block><block s="doReport"><l>2</l></block></script><list></list></block><list></list></custom-block><block s="reifyReporter"><script><block s="doWait"><l>.5</l></block><block s="doReport"><block s="reportVariadicProduct"><list><l></l><l>2</l></list></block></block></script><list></list></block><comment w="269.1666666666667" collapsed="false">create a promise that does actions after another promise. errors in the first promise stay in the new one.</comment></custom-block></script><script x="20" y="972.5"><custom-block s="%s catch %repRing"><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>.5</l></block></script><list></list></block><list></list></custom-block><block s="reifyReporter"><script><block s="doSayFor"><l></l><l>2</l></block></script><list></list></block><comment w="285" collapsed="false">create a promise that catches an error from a promise. if there&apos;s no error, it acts the same as the original promise.</comment></custom-block></script><comment x="20" y="1041.5" w="248.33333333333334" collapsed="false">if a promise is already complete when anything that waits for it runs, they run immediately</comment><script x="20" y="1107.5"><block s="doDeclareVariables"><list><l>promise</l><l>start time</l><l>clone</l></list></block><block s="doSetVar"><l>clone</l><block s="newClone"><l><option>myself</option></l></block></block><block s="doSetVar"><l>promise</l><block s="reportAskFor"><block var="clone"/><block s="reifyReporter"><autolambda><custom-block s="promise %repRing %inputs"><block s="reifyReporter"><script><block s="doWait"><l>.5</l></block><block s="doDeclareVariables"><list><l>rand</l></list></block><block s="doSetVar"><l>rand</l><block s="reportRandom"><l>1</l><l>4</l></block></block><block s="doIf"><block s="reportEquals"><block var="rand"/><l>1</l></block><script><block s="doReport"><block s="reportJoinWords"><list><l>number </l><block s="reportRandom"><l>1</l><l>9</l></block></list></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="rand"/><l>2</l></block><script><custom-block s="error %txt"><block s="reportJoinWords"><list><l>error </l><block s="reportRandom"><l>1</l><l>9</l></block></list></block></custom-block></script></block><block s="doIf"><block s="reportEquals"><block var="rand"/><l>3</l></block><script><block s="doForever"><script><block s="doGotoObject"><l><option>random position</option></l></block><block s="setHeading"><l><option>random</option></l></block></script></block></script></block></script><list></list></block><list></list></custom-block></autolambda><list></list></block><list></list></block><comment w="165" collapsed="false">this could do all sorts of things!</comment></block><block s="doSetVar"><l>start time</l><block s="reportDate"><l><option>time in milliseconds</option></l></block></block><block s="bubble"><l>waiting...</l></block><block s="doWaitUntil"><block s="reportOr"><custom-block s="%s is complete?"><block var="promise"/></custom-block><block s="reportGreaterThan"><block s="reportDate"><l><option>time in milliseconds</option></l></block><block s="reportVariadicSum"><list><block var="start time"/><l>5000</l></list></block></block></block></block><block s="doIfElse"><custom-block s="%s is complete?"><block var="promise"/></custom-block><script><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSayFor"><block s="reportJoinWords"><list><l>done: </l><block s="evaluate"><block s="reifyReporter"><script><custom-block s="await %s"><block var="promise"/></custom-block><block s="doReport"><l>didn&apos;t report</l></block></script><list></list></block><list></list></block></list></block><l>1</l></block></script><l>error</l><script><block s="doSayFor"><block s="reportJoinWords"><list><l>failed with error: </l><block var="error"/></list></block><l>1</l></block></script></custom-block></script><script><block s="doTellTo"><block var="clone"/><block s="reifyScript"><script><block s="doStopThis"><l><option>other scripts in sprite</option></l></block></script><list></list></block><list></list></block><block s="doSayFor"><l>didn&apos;t complete fast enough!</l><l>1</l></block></script></block><block s="doTellTo"><block var="clone"/><block s="reifyScript"><script><block s="removeClone"></block></script><list></list></block><list></list></block></script></scripts></sprite></sprites></stage><variables></variables></scene></scenes></project><media name="Promises library" app="Snap! 7, https://snap.berkeley.edu" version="2"></media></snapdata>