function run(gen) {
const g = gen()
function next(data) {
const result = g.next(data);
if (result.done) return result.value;
result.value.then(res => {
next(res)
})
}
next()
}
function* gen() {
const response1 = yield fetch('http://localhost:10003/api/sys_user/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: '1', password: '1' })
})
const json1 = yield response1.json();
console.log(json1)
const response2 = yield fetch('http://localhost:10003/api/sys_user/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'yqkj', password: '123456' })
})
const json2 = yield response2.json();
console.log(json2)
}
function* gen2() {
const a = yield new Promise(resolve => {
setTimeout(() => {
resolve('1')
}, 1000)
})
console.log(a)
const b = yield new Promise(resolve => {
setTimeout(() => {
resolve('2')
}, 1000)
})
console.log(b)
}
// run(gen2)
// run(gen)
console