dkogler.github.io:Greenlight Web开发

  • h8_205902
    了解作者
  • 11.7MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-11 19:01
    上传日期
dkogler.github.io 固定链接:/index.html Greenlight Web开发
dkogler_github_io-master.zip
内容介绍
<a href="http://promisesaplus.com/" rel='nofollow' onclick='return false;'> <img src="http://promisesaplus.com/assets/logo-small.png" alt="Promises/A+ logo" title="Promises/A+ 1.1 compliant" align="right" /> </a> [![Build Status](https://travis-ci.org/petkaantonov/bluebird.svg?branch=master)](https://travis-ci.org/petkaantonov/bluebird) [![coverage-98%](http://img.shields.io/badge/coverage-98%-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html) # 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](API.md) - [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](https://github.com/petkaantonov/bluebird/wiki/Snippets) - [Promise anti-patterns](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns) - [Changelog](changelog.md) - [Optimization guide](#optimization-guide) # Features <img src="http://petkaantonov.github.io/bluebird/logo.png" alt="bluebird logo" align="right" /> - [Promises A+](http://promisesaplus.com) - [Synchronous inspection](API.md#synchronous-inspection) - [Concurrency coordination](API.md#collections) - [Promisification on steroids](API.md#promisification) - [Resource management through a parallel of python `with`/C# `using`](API.md#resource-management) - [Cancellation and timeouts](API.md#cancellation) - [Parallel for C# `async` and `await`](API.md#generators) - Mind blowing utilities such as - [`.bind()`](API.md#binddynamic-thisarg---promise) - [`.call()`](API.md#callstring-propertyname--dynamic-arg---promise) - [`Promise.join()`](API.md#promisejoinpromisethenablevalue-promises-function-handler---promise) - [And](API.md#core) [much](API.md#timers) [more](API.md#utility)! - [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](https://cdn.jsdelivr.net/bluebird/latest/bluebird.js) - Full build minified [bluebird.min.js](https://cdn.jsdelivr.net/bluebird/latest/bluebird.min.js) - You may use browserify on the main export - You may use the [bower](http://bower.io) 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](http://en.wikipedia.org/wiki/Ecmascript#Implementations) and later are supported. [![Selenium Test Status](https://saucelabs.com/browser-matrix/petka_antonov.svg)](https://saucelabs.com/u/petka_antonov) **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](API.md) 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](API.md#promiselongstacktraces---void) support is only available in Chrome, Firefox and Internet Explorer 10+. After quick start, see [API Reference and examples](API.md) <hr> # Support - Mailing list: [bluebird-js@googlegroups.com](https://groups.google.com/forum/#!forum/bluebird-js) - IRC: #promises @freenode - StackOverflow: [bluebird tag](http://stackoverflow.com/questions/tagged/bluebird) - Bugs and feature requests: [github issue tracker](https://github.com/petkaantonov/bluebird/issues?state=open) <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](API.md#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 http://stackoverflow.com/a/19385911/995876 //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(); Promise.map(URLs, 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](https://promise-nuggets.github.io/) - [Why I am switching to promises](http://spion.github.io/posts/why-i-am-switching-to-promises.html) - [What is the the point of promises](http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/#toc_1) - [Snippets for common problems](https://github.com/petkaantonov/bluebird/wiki/Snippets) - [Promise anti-patterns](https://github.com/petkaantonov/bluebird/wiki/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](https://github.com/petkaantonov/bluebird/issues). 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 向脚本添
    • GITHTML
      GITHTML
    • 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...