-
Notifications
You must be signed in to change notification settings - Fork 1
/
unused.js
31 lines (31 loc) · 995 Bytes
/
unused.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Block#run
const AsyncFunction = async function(){}.constructor
const GeneratorFunction = function*(){}.constructor
const AsyncGenerator = async function*(){}.constructor
try {
const result = scope.eval(this.code)
console.log('result', result)
if(result instanceof Promise){
this.type = 'async'
this.result = await result
}
// if(result && (result[Symbol.toStringTag] === 'Generator' || result[Symbol.toStringTag] === 'AsyncGenerator')){
else if(result instanceof GeneratorFunction){
for(let generator = result, value, done; {value, done} = generator.next(), !done; ){
this.result = value
this.state = 'changed'
await new Promise(r => requestAnimationFrame(r))
}
}
else if(result instanceof AsyncGenerator){
for(let generator = result, value, done; {value, done} = await generator.next(), !done; ){
this.result = value
this.state = 'changed'
await new Promise(r => requestAnimationFrame(r))
}
}
else{
this.result = result
this.state = 'changed'
}
}