我在浏览器中工作并希望同时运行两个ajax请求 - 不按顺序。所以我产生一个像这样的对象或数组:
// yield object
Promise.coroutine(function* () {
var data = yield {
tweets: $.get('tweets.json'),
profile: yield $.get('profile.json')
};
console.log(data.tweets, data.profile);
})();
// yield array
Promise.coroutine(function* () {
var [tweets, profile] = yield [$.get('tweets.json'), yield $.get('profile.json')];
console.log(tweets, profile);
})();
但这会引发错误:
A value [object Object],[object Object] was yielded that could not be treated as a promise
我做错了什么?我该如何解决这个问题?