我使用JS生成器在Axiom supremum :forall E:R -> Prop,
(exists l : R,is_upper_bound E l) ->
(exists x : R, E x) ->
{ m:R | is_lub E m /\ (forall x:R, x<m -> exists y:R,(E y /\ y >x))}.
:
setTimeout
为什么我不能在生成器的回调中产生值?
答案 0 :(得分:12)
function*
声明是同步的。您可以生成一个新的Promise
对象,链.then()
到.next().value
以检索已解决的Promise
值
function* sleep() {
yield new Promise(resolve => {
setTimeout(() => {
resolve(5);
}, 5000);
})
}
// sync
const sleepTime = sleep().next().value
.then(n => console(n))
.catch(e => console.error(e));