Skip to content

Instantly share code, notes, and snippets.

@espio999
Last active February 21, 2026 02:54
Show Gist options
  • Select an option

  • Save espio999/8049a12843f747bf65fb883236e8db96 to your computer and use it in GitHub Desktop.

Select an option

Save espio999/8049a12843f747bf65fb883236e8db96 to your computer and use it in GitHub Desktop.
<html>
<head>
<script>
let isInlineExecuted = false;
/*
let unlock = null;
let forceOpen = null;
const gate = new Promise((resolve, reject) => {
unlock = resolve;
forceOpen = reject;
});
*/
const {
promise: gate,
resolve: unlock,
reject: forceOpen
} = Promise.withResolvers();
</script>
<script>
function wait_long(){
const t = 10000;
const f = () => {
console.log("お待たせ");
unlock();
console.log("unlock");
}
setTimeout(f, t);
}
function inline_logic(){
isInlineExecuted = true;
try{
console.log("inline logic - start");
if (Math.random() < 0.5) {
throw new Error("error occured in inline logic");
}
wait_long();
console.log("inline logic - completed");
}
catch (e){
console.log(e);
forceOpen();
}
}
if (Math.random() < 0.5) {
inline_logic();
}
else{
console.log("inline logic - skipped");
unlock();
console.log("unlock");
}
</script>
<script src="promise-unlock.js"></script>
</head>
<body></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment