Last active
June 4, 2018 14:13
-
-
Save iamdvr/ff16cfd6e357738d071495ae6047c368 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/wigegeqiyi
This file contains 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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<textarea rows="10" cols="50" name="console">N/A</textarea> | |
<input type="button" onclick="javascript:callSomeAsyncThing();" value="ClickMe" /> | |
<input type="button" onclick="javascript:clearData();" value="Clear" /> | |
<script id="jsbin-javascript"> | |
var clearData = function() { | |
document.getElementsByName("console")[0].value = ""; | |
}; | |
var delayFun = function (delay) { | |
var preTime = new Date().getTime(); | |
var loopCnt = 0; | |
while (true) {// noprotect | |
var diff = (new Date().getTime()) - preTime; | |
if (diff > delay) { | |
console.log( diff + ' - ' + delay + ' : ' + loopCnt); | |
break; | |
}else{ | |
loopCnt++; | |
} | |
} | |
}; | |
var someAsyncThing = function() { | |
return new Promise(function(resolve, reject) { | |
// this will throw, x does not exist | |
var x = 4; | |
var preDate = new Date(); | |
delayFun(300); | |
var postDate = new Date(); | |
resolve(preDate + "\r\r" + postDate); | |
}); | |
}; | |
var callSomeAsyncThing = function() { | |
someAsyncThing() | |
.then(function(data) { | |
document.getElementsByName("console")[0].value = data; | |
}) | |
.catch(function(error) { | |
console.log('oh no', error); | |
}); | |
}; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
var clearData = function() { | |
document.getElementsByName("console")[0].value = ""; | |
}; | |
var delayFun = function (delay) { | |
var preTime = new Date().getTime(); | |
var loopCnt = 0; | |
while (true) {// noprotect | |
var diff = (new Date().getTime()) - preTime; | |
if (diff > delay) { | |
console.log( diff + ' - ' + delay + ' : ' + loopCnt); | |
break; | |
}else{ | |
loopCnt++; | |
} | |
} | |
}; | |
var someAsyncThing = function() { | |
return new Promise(function(resolve, reject) { | |
// this will throw, x does not exist | |
var x = 4; | |
var preDate = new Date(); | |
delayFun(300); | |
var postDate = new Date(); | |
resolve(preDate + "\r\r" + postDate); | |
}); | |
}; | |
var callSomeAsyncThing = function() { | |
someAsyncThing() | |
.then(function(data) { | |
document.getElementsByName("console")[0].value = data; | |
}) | |
.catch(function(error) { | |
console.log('oh no', error); | |
}); | |
}; | |
</script></body> | |
</html> |
This file contains 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 characters
var clearData = function() { | |
document.getElementsByName("console")[0].value = ""; | |
}; | |
var delayFun = function (delay) { | |
var preTime = new Date().getTime(); | |
var loopCnt = 0; | |
while (true) {// noprotect | |
var diff = (new Date().getTime()) - preTime; | |
if (diff > delay) { | |
console.log( diff + ' - ' + delay + ' : ' + loopCnt); | |
break; | |
}else{ | |
loopCnt++; | |
} | |
} | |
}; | |
var someAsyncThing = function() { | |
return new Promise(function(resolve, reject) { | |
// this will throw, x does not exist | |
var x = 4; | |
var preDate = new Date(); | |
delayFun(300); | |
var postDate = new Date(); | |
resolve(preDate + "\r\r" + postDate); | |
}); | |
}; | |
var callSomeAsyncThing = function() { | |
someAsyncThing() | |
.then(function(data) { | |
document.getElementsByName("console")[0].value = data; | |
}) | |
.catch(function(error) { | |
console.log('oh no', error); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment