• h8_205902
  • 11.7MB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-04-11 19:01
    上传日期 固定链接:/index.html Greenlight Web开发
<a href="" rel='nofollow' onclick='return false;'> <img src="" alt="Promises/A+ logo" title="Promises/A+ 1.1 compliant" align="right" /> </a> [![Build Status](]( [![coverage-98%](]( # Introduction Bluebird is a fully featured [promise](#what-are-promises-and-why-should-i-use-them) library with focus on innovative features and performance # Topics - [Features](#features) - [Quick start](#quick-start) - [API Reference and examples]( - [Support](#support) - [What are promises and why should I use them?](#what-are-promises-and-why-should-i-use-them) - [Questions and issues](#questions-and-issues) - [Error handling](#error-handling) - [Development](#development) - [Testing](#testing) - [Benchmarking](#benchmarks) - [Custom builds](#custom-builds) - [For library authors](#for-library-authors) - [What is the sync build?](#what-is-the-sync-build) - [License](#license) - [Snippets for common problems]( - [Promise anti-patterns]( - [Changelog]( - [Optimization guide](#optimization-guide) # Features <img src="" alt="bluebird logo" align="right" /> - [Promises A+]( - [Synchronous inspection]( - [Concurrency coordination]( - [Promisification on steroids]( - [Resource management through a parallel of python `with`/C# `using`]( - [Cancellation and timeouts]( - [Parallel for C# `async` and `await`]( - Mind blowing utilities such as - [`.bind()`]( - [`.call()`]( - [`Promise.join()`]( - [And]( [much]( [more](! - [Practical debugging solutions and sane defaults](#error-handling) - [Sick performance](benchmark/) <hr> # Quick start ## Node.js npm install bluebird Then: ```js var Promise = require("bluebird"); ``` ## Browsers There are many ways to use bluebird in browsers: - Direct downloads - Full build [bluebird.js]( - Full build minified [bluebird.min.js]( - You may use browserify on the main export - You may use the [bower]( package. When using script tags the global variables `Promise` and `P` (alias for `Promise`) become available. A [minimal bluebird browser build](#custom-builds) is &asymp;38.92KB minified*, 11.65KB gzipped and has no external dependencies. *Google Closure Compiler using Simple. #### Browser support Browsers that [implement ECMA-262, edition 3]( and later are supported. [![Selenium Test Status](]( **Note** that in ECMA-262, edition 3 (IE7, IE8 etc.) it is not possible to use methods that have keyword names like `.catch` and `.finally`. The [API documentation]( always lists a compatible alternative name that you can use if you need to support these browsers. For example `.catch` is replaced with `.caught` and `.finally` with `.lastly`. Also, [long stack trace]( support is only available in Chrome, Firefox and Internet Explorer 10+. After quick start, see [API Reference and examples]( <hr> # Support - Mailing list: [](!forum/bluebird-js) - IRC: #promises @freenode - StackOverflow: [bluebird tag]( - Bugs and feature requests: [github issue tracker]( <hr> # What are promises and why should I use them? You should use promises to turn this: ```js fs.readFile("file.json", function(err, val) { if( err ) { console.error("unable to read file"); } else { try { val = JSON.parse(val); console.log(val.success); } catch( e ) { console.error("invalid json in file"); } } }); ``` Into this: ```js fs.readFileAsync("file.json").then(JSON.parse).then(function(val) { console.log(val.success); }) .catch(SyntaxError, function(e) { console.error("invalid json in file"); }) .catch(function(e) { console.error("unable to read file") }); ``` *If you are wondering "there is no `readFileAsync` method on `fs` that returns a promise", see [promisification](* Actually you might notice the latter has a lot in common with code that would do the same using synchronous I/O: ```js try { var val = JSON.parse(fs.readFileSync("file.json")); console.log(val.success); } //Syntax actually not supported in JS but drives the point catch(SyntaxError e) { console.error("invalid json in file"); } catch(Error e) { console.error("unable to read file") } ``` And that is the point - being able to have something that is a lot like `return` and `throw` in synchronous code. You can also use promises to improve code that was written with callback helpers: ```js //Copyright Plato //CC BY-SA 2.5 mapSeries(URLs, function (URL, done) { var options = {}; needle.get(URL, options, function (error, response, body) { if (error) { return done(error) } try { var ret = JSON.parse(body); return done(null, ret); } catch (e) { done(e); } }); }, function (err, results) { if (err) { console.log(err) } else { console.log('All Needle requests successful'); // results is a 1 to 1 mapping in order of URLs > needle.body processAndSaveAllInDB(results, function (err) { if (err) { return done(err) } console.log('All Needle requests saved'); done(null); }); } }); ``` Is more pleasing to the eye when done with promises: ```js Promise.promisifyAll(needle); var options = {}; var current = Promise.resolve();, function(URL) { current = current.then(function () { return needle.getAsync(URL, options); }); return current; }).map(function(responseAndBody){ return JSON.parse(responseAndBody[1]); }).then(function (results) { return processAndSaveAllInDB(results); }).then(function(){ console.log('All Needle requests saved'); }).catch(function (e) { console.log(e); }); ``` Also promises don't just give you correspondences for synchronous features but can also be used as limited event emitters or callback aggregators. More reading: - [Promise nuggets]( - [Why I am switching to promises]( - [What is the the point of promises]( - [Snippets for common problems]( - [Promise anti-patterns]( # Questions and issues If you find a bug in bluebird or have a feature request, file an issue in the [github issue tracker]( Anything else, such as questio
    • GitProject
      <title> HTML链接</ title> HTML:超文本标记语言 蒂姆·伯纳斯·李(Tim Berners-Lee)在欧洲核子研究组织(CERN)发明了首个浏览器,以使研究人员能够彼此共享研究成果。
    • git_bsp
      hft-asgmt-git 去做 创建一个index.html文件 推送回购
    • HTML_Git:活动4来自GitLab
      HTML_Git 活动4来自GitLab
    • gitnotify:发送彩色 html git diffs 的简单 shell 脚本
      概括 gitnotify 是一个简单的 shell 脚本,旨在从钩子发送漂亮的 ... echo ' [ -x ~/bin/gitnotify ] && ~/bin/gitnotify -m your@email.address -s "[DIFF] My repo notify" ' >> .git/hooks/post-commit 向脚本添
    • git-puesto-en-practica:Git入门HTML演示
      git 以实用和可视化的介绍介绍Git。 网址: :
    • GIT常用命令整理
      GIT常用命令整理,包含一个HTML文档,一个PNG脑图: 配置操作、 全局配置、 局部配置、 基本操作、 分支操作、 合并操作、 标签操作、 回滚操作、 本地文件回滚、 日志操作、 远程操作。
    • GHUP_HTML:使用htmlgit hub用户页面
      GHUP_HTML 使用htmlgit hub用户页面
    • htmldocs:预先构建HTML Git文档
      htmldocs:预先构建HTML Git文档
    • gitpractice:Git实践
      Git简介 商标 我们正在添加第一个文件 家 主页位于home.html 关于 关于页面 胡安·佩奇(Juan Page) Juan与该项目的合作可以在juan.html中找到 艾琳页面 可在ailin-linares.html上找到Ailin与该项目的合作 Flavia...