js Promise fetch demo
<html>
<head>
<title></title>
</head>
<body>
</body>
<script type="text/javascript">
function worker(url, url_2, i){
return new Promise(function(resolve, reject){
fetch(url).then(function(response_out) {
response_out.text().then(
function(outer_text){
console.log(i + " 外部完成");
fetch(url_2).then(function(response_in) {
var inner_text = response_in.text().then(function(inner_text){
console.log(i + " 内部完成");
resolve( outer_text + " + " + inner_text);
});
});
}
);
})
});
} var worker_list = [];
for (var i=0; i<10; i++){
var url = 'data.txt';
var url_2 = 'data2.txt';
var w = worker(url, url_2, i);
worker_list.push(w);
} Promise.all(worker_list).then(function(all_result_list){
console.log("都完成了");
console.log(all_result_list);
});
</script>
</html>
js Promise fetch demo的更多相关文章
- JS - Promise使用详解--摘抄笔记
第一部分: JS - Promise使用详解1(基本概念.使用优点) 一.promises相关概念 promises 的概念是由 CommonJS 小组的成员在 Promises/A 规范中提出来的. ...
- js Promise finally All In One
js Promise finally All In One finally let isLoading = true; fetch(myRequest).then(function(response) ...
- JS之Fetch
细节叙述见以下链接:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch 1 基本概念: WindowOrWo ...
- [转]JS - Promise使用详解1(基本概念、使用优点)
一.promises相关概念 promises 的概念是由 CommonJS 小组的成员在 Promises/A 规范中提出来的. 1,then()方法介绍 根据 Promise/A 规范,pro ...
- 在线浏览PDF之PDF.JS (附demo)
平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...
- js promise chain
新的标准里增加了原生的Promise. 这里只讨论链式使用的情况,思考一下其中的细节部分. 一,关于 then() 和 catch() 的复习 then() 和 catch() 的参数里可以放置 ca ...
- [Node.js] Promise,Q及Async
原文地址:http://www.moye.me/2014/12/27/promise_q_async/ 引子 在使用Node/JS编程的时候,经常会遇到这样的问题:有一连串的异步方法,需要按顺序执行, ...
- ANGULAR JS PROMISE使用
Promise是一种模式,以同步操作的流程形式来操作异步事件,避免了层层嵌套,可以链式操作异步事件. 我们知道,在编写javascript异步代码时,callback是最最简单的机制,可是用这种机制的 ...
- Async CallBack promise fetch
Callback (回调函数) 在计算机程序设计中,回调函数,或简称回调(Callback 即call then back 被主函数调用运算后会返回主函数),是指通过函数参数传递到其它代码的,某一块可 ...
随机推荐
- vscode代码保存时自动格式化成ESLint风格(支持VUE)
一.问题 vscode的默认的代码格式化ctrl+shift+f 无法通过eslint的代码风格检查是一个非常蛋疼的问题 同样在进行vue项目开发的时候,使用eslint代码风格检查是没啥问题的,但是 ...
- nginx补丁格式说明(CVE-2016-4450为例)
nginx安全公告地址:http://nginx.org/en/security_advisories.html CVE-2016-4450:一个特定构造的数据包,可引发nginx引用空指针,导致ng ...
- Sql server中如何将表A和表B的数据合并(乘积方式)
sql server中如何将表A 和表B的数据合并成乘积方式,也就是说表A有2条数据,表B有3条数据,乘积后有6条数据, 这就要用到sql中的笛卡尔积方式了 1.什么是笛卡尔积 笛卡尔积在SQL中的实 ...
- 外部调用mvc的api方法时,如何解决跨域请求问题?
首先,创建一个mvc项目(包含webapi),我们模拟一个场景 1)在项目的Controller 创建一个WeiXinApiController public class WeiXinApiContr ...
- javascript 多个onclick function 取对应值
方法1: 直接获取值 <button onclick="aa(1)">执行</button> <button onclick="aa(2)& ...
- C++11 并发之std::thread std::mutex
https://www.cnblogs.com/whlook/p/6573659.html (https://www.cnblogs.com/lidabo/p/7852033.html) C++:线程 ...
- Cyclic Components CodeForces - 977E(DFS)
Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and ...
- asp.net mvc 笔记一
webapi controller 中 action 名称 不能与 View controller 中的 action 名称相同,否则 Url.Action("actionName&quo ...
- 认识微软Visual Studio Tools for AI
认识微软Visual Studio Tools for AI 微软已经发布了其 Visual Studio Tools for AI 的测试版本,这是微软 Visual Studio 2017 I ...
- HTML5 ③
超链接和锚链接: 1.超链接标签:<a herf="需要连接的页面地址" target=“01._self :在当前页面打开 *默认值 02. _blank :新窗口 ...