Last active
March 12, 2016 20:41
-
-
Save soapdog/0130b10a84e9cd5328f8 to your computer and use it in GitHub Desktop.
Revisions
-
soapdog revised this gist
Mar 12, 2016 . 1 changed file with 10 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,26 +4,22 @@ function makePromise() { }); } var gambiwrap = function(p) { console.log("Promessa não resolvida"); return p.then(function(r) { gambiwrap = function() { console.log("Promessa resolvida"); return r; } }) } console.log("primeira chamada...") gambiwrap(makePromise()); console.log("Agora chama vc gambiwrap(makePromise())"); -
soapdog created this gist
Mar 12, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ function makePromise() { return new Promise(function(resolve, reject){ setTimeout(function(){ resolve('hey!') }, 500); }); } function gambiwrap(p) { if (!gambiwrap.cachedResult) { console.log("Promise não resolvida..."); return p.then(function(r) { gambiwrap.cachedResult = r; }) } else { console.log("Já resolveu essa porra"); return gambiwrap.cachedResult; } } console.log("primeira chamada...") var p = gambiwrap(makePromise()); console.log(p); console.log("Agora chama vc essa porra com p = gambiwrap(makePromise())");