browsed 0.2.9 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +28 -28
- data/browsed.gemspec +3 -4
- data/lib/browsed.rb +1 -1
- data/lib/browsed/chrome.rb +2 -2
- data/lib/browsed/client.rb +2 -2
- data/lib/browsed/firefox.rb +2 -2
- data/lib/browsed/version.rb +1 -1
- metadata +13 -166
- data/lib/browsed/proxies/proxy-chain-server/node_modules/.bin/portastic +0 -1
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/LICENSE +0 -21
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/README.md +0 -57
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/changelog.md +0 -1
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.js +0 -3824
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.core.min.js +0 -31
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.js +0 -5666
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/any.js +0 -21
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/assert.js +0 -55
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/async.js +0 -165
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bind.js +0 -67
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/bluebird.js +0 -11
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/call_get.js +0 -123
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/cancel.js +0 -129
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/catch_filter.js +0 -42
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/context.js +0 -69
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/debuggability.js +0 -934
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/direct_resolve.js +0 -46
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/each.js +0 -30
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/errors.js +0 -116
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/es5.js +0 -80
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/filter.js +0 -12
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/finally.js +0 -146
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/generators.js +0 -223
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/join.js +0 -168
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/map.js +0 -168
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/method.js +0 -55
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeback.js +0 -51
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/nodeify.js +0 -58
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise.js +0 -789
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promise_array.js +0 -185
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/promisify.js +0 -314
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/props.js +0 -118
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/queue.js +0 -73
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/race.js +0 -49
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/reduce.js +0 -172
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/schedule.js +0 -62
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/settle.js +0 -43
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/some.js +0 -148
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/synchronous_inspection.js +0 -103
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/thenables.js +0 -86
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/timers.js +0 -93
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/using.js +0 -226
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/js/release/util.js +0 -389
- data/lib/browsed/proxies/proxy-chain-server/node_modules/bluebird/package.json +0 -102
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/CHANGELOG.md +0 -408
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/LICENSE +0 -22
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/Readme.md +0 -428
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/index.js +0 -1224
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/package.json +0 -70
- data/lib/browsed/proxies/proxy-chain-server/node_modules/commander/typings/index.d.ts +0 -310
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.coveralls.yml +0 -1
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.eslintrc +0 -11
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.npmignore +0 -9
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/.travis.yml +0 -14
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/CHANGELOG.md +0 -362
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/LICENSE +0 -19
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/Makefile +0 -50
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/README.md +0 -312
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/component.json +0 -19
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/karma.conf.js +0 -70
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/node.js +0 -1
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/package.json +0 -88
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/browser.js +0 -185
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/debug.js +0 -202
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/index.js +0 -10
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/inspector-log.js +0 -15
- data/lib/browsed/proxies/proxy-chain-server/node_modules/debug/src/node.js +0 -248
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/index.js +0 -152
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/license.md +0 -21
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/package.json +0 -69
- data/lib/browsed/proxies/proxy-chain-server/node_modules/ms/readme.md +0 -51
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/LICENSE +0 -13
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/README.md +0 -148
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/bin/portastic +0 -65
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/history.md +0 -7
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/index.js +0 -4
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/monitor.js +0 -59
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/lib/portastic.js +0 -167
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE +0 -21
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md +0 -677
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/changelog.md +0 -1730
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.js +0 -4892
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/browser/bluebird.min.js +0 -31
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/any.js +0 -21
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/assert.js +0 -55
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/async.js +0 -150
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bind.js +0 -72
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/bluebird.js +0 -11
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/call_get.js +0 -123
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/cancel.js +0 -48
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/captured_trace.js +0 -493
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/catch_filter.js +0 -66
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/context.js +0 -38
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/debuggability.js +0 -162
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/direct_resolve.js +0 -63
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/each.js +0 -12
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/errors.js +0 -111
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/es5.js +0 -80
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/filter.js +0 -12
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/finally.js +0 -98
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/generators.js +0 -136
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/join.js +0 -107
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/map.js +0 -133
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/method.js +0 -44
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/nodeify.js +0 -59
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/progress.js +0 -76
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise.js +0 -759
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_array.js +0 -142
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promise_resolver.js +0 -123
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/promisify.js +0 -307
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/props.js +0 -79
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/queue.js +0 -90
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/race.js +0 -47
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/reduce.js +0 -148
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/schedule.js +0 -35
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/settle.js +0 -40
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/some.js +0 -125
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/synchronous_inspection.js +0 -94
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/thenables.js +0 -84
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/timers.js +0 -64
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/using.js +0 -213
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/js/main/util.js +0 -321
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/package.json +0 -103
- data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/package.json +0 -69
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/CHANGELOG.md +0 -109
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/LICENSE +0 -201
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/README.md +0 -278
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/anonymize_proxy.js +0 -100
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_base.js +0 -319
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_custom_response.js +0 -96
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_forward.js +0 -173
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_chain.js +0 -132
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_direct.js +0 -89
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/handler_tunnel_tcp_chain.js +0 -271
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/index.js +0 -26
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/run_locally.js +0 -66
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/server.js +0 -595
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tcp_tunnel.js +0 -138
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/testing_tcp_service.js +0 -37
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/build/tools.js +0 -220
- data/lib/browsed/proxies/proxy-chain-server/node_modules/proxy-chain/package.json +0 -104
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/LICENSE +0 -23
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/README.md +0 -28
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/package.json +0 -81
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js +0 -5
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore-min.js.map +0 -1
- data/lib/browsed/proxies/proxy-chain-server/node_modules/underscore/underscore.js +0 -1692
- data/lib/browsed/proxies/proxy-chain-server/package-lock.json +0 -63
- data/lib/browsed/proxies/proxy-chain-server/package.json +0 -15
- data/lib/browsed/proxies/proxy-chain-server/server.js +0 -25
- data/lib/browsed/proxies/proxy_chain.rb +0 -39
data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2013-2015 Petka Antonov
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/lib/browsed/proxies/proxy-chain-server/node_modules/portastic/node_modules/bluebird/README.md
DELETED
@@ -1,677 +0,0 @@
|
|
1
|
-
<a href="http://promisesaplus.com/">
|
2
|
-
<img src="http://promisesaplus.com/assets/logo-small.png" alt="Promises/A+ logo"
|
3
|
-
title="Promises/A+ 1.1 compliant" align="right" />
|
4
|
-
</a>
|
5
|
-
[![Build Status](https://travis-ci.org/petkaantonov/bluebird.svg?branch=master)](https://travis-ci.org/petkaantonov/bluebird)
|
6
|
-
[![coverage-98%](http://img.shields.io/badge/coverage-98%-brightgreen.svg?style=flat)](http://petkaantonov.github.io/bluebird/coverage/debug/index.html)
|
7
|
-
|
8
|
-
**Got a question?** Join us on [stackoverflow](http://stackoverflow.com/questions/tagged/bluebird), the [mailing list](https://groups.google.com/forum/#!forum/bluebird-js) or chat on [IRC](https://webchat.freenode.net/?channels=#promises)
|
9
|
-
|
10
|
-
# Introduction
|
11
|
-
|
12
|
-
Bluebird is a fully featured [promise](#what-are-promises-and-why-should-i-use-them) library with focus on innovative features and performance
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# Topics
|
17
|
-
|
18
|
-
- [Features](#features)
|
19
|
-
- [Quick start](#quick-start)
|
20
|
-
- [API Reference and examples](API.md)
|
21
|
-
- [Support](#support)
|
22
|
-
- [What are promises and why should I use them?](#what-are-promises-and-why-should-i-use-them)
|
23
|
-
- [Questions and issues](#questions-and-issues)
|
24
|
-
- [Error handling](#error-handling)
|
25
|
-
- [Development](#development)
|
26
|
-
- [Testing](#testing)
|
27
|
-
- [Benchmarking](#benchmarks)
|
28
|
-
- [Custom builds](#custom-builds)
|
29
|
-
- [For library authors](#for-library-authors)
|
30
|
-
- [What is the sync build?](#what-is-the-sync-build)
|
31
|
-
- [License](#license)
|
32
|
-
- [Snippets for common problems](https://github.com/petkaantonov/bluebird/wiki/Snippets)
|
33
|
-
- [Promise anti-patterns](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns)
|
34
|
-
- [Changelog](changelog.md)
|
35
|
-
- [Optimization guide](#optimization-guide)
|
36
|
-
|
37
|
-
# Features
|
38
|
-
<img src="http://petkaantonov.github.io/bluebird/logo.png" alt="bluebird logo" align="right" />
|
39
|
-
|
40
|
-
- [Promises A+](http://promisesaplus.com)
|
41
|
-
- [Synchronous inspection](API.md#synchronous-inspection)
|
42
|
-
- [Concurrency coordination](API.md#collections)
|
43
|
-
- [Promisification on steroids](API.md#promisification)
|
44
|
-
- [Resource management through a parallel of python `with`/C# `using`](API.md#resource-management)
|
45
|
-
- [Cancellation and timeouts](API.md#cancellation)
|
46
|
-
- [Parallel for C# `async` and `await`](API.md#generators)
|
47
|
-
- Mind blowing utilities such as
|
48
|
-
- [`.bind()`](API.md#binddynamic-thisarg---promise)
|
49
|
-
- [`.call()`](API.md#callstring-propertyname--dynamic-arg---promise)
|
50
|
-
- [`Promise.join()`](API.md#promisejoinpromisethenablevalue-promises-function-handler---promise)
|
51
|
-
- [And](API.md#core) [much](API.md#timers) [more](API.md#utility)!
|
52
|
-
- [Practical debugging solutions and sane defaults](#error-handling)
|
53
|
-
- [Sick performance](benchmark/)
|
54
|
-
|
55
|
-
<hr>
|
56
|
-
|
57
|
-
# Quick start
|
58
|
-
|
59
|
-
## Node.js
|
60
|
-
|
61
|
-
npm install bluebird
|
62
|
-
|
63
|
-
Then:
|
64
|
-
|
65
|
-
```js
|
66
|
-
var Promise = require("bluebird");
|
67
|
-
```
|
68
|
-
|
69
|
-
## Browsers
|
70
|
-
|
71
|
-
There are many ways to use bluebird in browsers:
|
72
|
-
|
73
|
-
- Direct downloads
|
74
|
-
- Full build [bluebird.js](https://cdn.jsdelivr.net/bluebird/2.10.2/bluebird.js)
|
75
|
-
- Full build minified [bluebird.min.js](https://cdn.jsdelivr.net/bluebird/2.10.2/bluebird.min.js)
|
76
|
-
- You may use browserify on the main export
|
77
|
-
- You may use the [bower](http://bower.io) package.
|
78
|
-
|
79
|
-
When using script tags the global variables `Promise` and `P` (alias for `Promise`) become available.
|
80
|
-
|
81
|
-
A [minimal bluebird browser build](#custom-builds) is ≈38.92KB minified*, 11.65KB gzipped and has no external dependencies.
|
82
|
-
|
83
|
-
*Google Closure Compiler using Simple.
|
84
|
-
|
85
|
-
#### Browser support
|
86
|
-
|
87
|
-
Browsers that [implement ECMA-262, edition 3](http://en.wikipedia.org/wiki/Ecmascript#Implementations) and later are supported.
|
88
|
-
|
89
|
-
[![Selenium Test Status](https://saucelabs.com/browser-matrix/petka_antonov.svg)](https://saucelabs.com/u/petka_antonov)
|
90
|
-
|
91
|
-
**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`.
|
92
|
-
|
93
|
-
Also, [long stack trace](API.md#promiselongstacktraces---void) support is only available in Chrome, Firefox and Internet Explorer 10+.
|
94
|
-
|
95
|
-
After quick start, see [API Reference and examples](API.md)
|
96
|
-
|
97
|
-
<hr>
|
98
|
-
|
99
|
-
# Support
|
100
|
-
|
101
|
-
- Mailing list: [bluebird-js@googlegroups.com](https://groups.google.com/forum/#!forum/bluebird-js)
|
102
|
-
- IRC: #promises @freenode
|
103
|
-
- StackOverflow: [bluebird tag](http://stackoverflow.com/questions/tagged/bluebird)
|
104
|
-
- Bugs and feature requests: [github issue tracker](https://github.com/petkaantonov/bluebird/issues?state=open)
|
105
|
-
|
106
|
-
<hr>
|
107
|
-
|
108
|
-
# What are promises and why should I use them?
|
109
|
-
|
110
|
-
You should use promises to turn this:
|
111
|
-
|
112
|
-
```js
|
113
|
-
fs.readFile("file.json", function(err, val) {
|
114
|
-
if( err ) {
|
115
|
-
console.error("unable to read file");
|
116
|
-
}
|
117
|
-
else {
|
118
|
-
try {
|
119
|
-
val = JSON.parse(val);
|
120
|
-
console.log(val.success);
|
121
|
-
}
|
122
|
-
catch( e ) {
|
123
|
-
console.error("invalid json in file");
|
124
|
-
}
|
125
|
-
}
|
126
|
-
});
|
127
|
-
```
|
128
|
-
|
129
|
-
Into this:
|
130
|
-
|
131
|
-
```js
|
132
|
-
fs.readFileAsync("file.json").then(JSON.parse).then(function(val) {
|
133
|
-
console.log(val.success);
|
134
|
-
})
|
135
|
-
.catch(SyntaxError, function(e) {
|
136
|
-
console.error("invalid json in file");
|
137
|
-
})
|
138
|
-
.catch(function(e) {
|
139
|
-
console.error("unable to read file");
|
140
|
-
});
|
141
|
-
```
|
142
|
-
|
143
|
-
*If you are wondering "there is no `readFileAsync` method on `fs` that returns a promise", see [promisification](API.md#promisification)*
|
144
|
-
|
145
|
-
Actually you might notice the latter has a lot in common with code that would do the same using synchronous I/O:
|
146
|
-
|
147
|
-
```js
|
148
|
-
try {
|
149
|
-
var val = JSON.parse(fs.readFileSync("file.json"));
|
150
|
-
console.log(val.success);
|
151
|
-
}
|
152
|
-
//Syntax actually not supported in JS but drives the point
|
153
|
-
catch(SyntaxError e) {
|
154
|
-
console.error("invalid json in file");
|
155
|
-
}
|
156
|
-
catch(Error e) {
|
157
|
-
console.error("unable to read file");
|
158
|
-
}
|
159
|
-
```
|
160
|
-
|
161
|
-
And that is the point - being able to have something that is a lot like `return` and `throw` in synchronous code.
|
162
|
-
|
163
|
-
You can also use promises to improve code that was written with callback helpers:
|
164
|
-
|
165
|
-
|
166
|
-
```js
|
167
|
-
//Copyright Plato http://stackoverflow.com/a/19385911/995876
|
168
|
-
//CC BY-SA 2.5
|
169
|
-
mapSeries(URLs, function (URL, done) {
|
170
|
-
var options = {};
|
171
|
-
needle.get(URL, options, function (error, response, body) {
|
172
|
-
if (error) {
|
173
|
-
return done(error);
|
174
|
-
}
|
175
|
-
try {
|
176
|
-
var ret = JSON.parse(body);
|
177
|
-
return done(null, ret);
|
178
|
-
}
|
179
|
-
catch (e) {
|
180
|
-
done(e);
|
181
|
-
}
|
182
|
-
});
|
183
|
-
}, function (err, results) {
|
184
|
-
if (err) {
|
185
|
-
console.log(err);
|
186
|
-
} else {
|
187
|
-
console.log('All Needle requests successful');
|
188
|
-
// results is a 1 to 1 mapping in order of URLs > needle.body
|
189
|
-
processAndSaveAllInDB(results, function (err) {
|
190
|
-
if (err) {
|
191
|
-
return done(err);
|
192
|
-
}
|
193
|
-
console.log('All Needle requests saved');
|
194
|
-
done(null);
|
195
|
-
});
|
196
|
-
}
|
197
|
-
});
|
198
|
-
```
|
199
|
-
|
200
|
-
Is more pleasing to the eye when done with promises:
|
201
|
-
|
202
|
-
```js
|
203
|
-
Promise.promisifyAll(needle);
|
204
|
-
var options = {};
|
205
|
-
|
206
|
-
var current = Promise.resolve();
|
207
|
-
Promise.map(URLs, function(URL) {
|
208
|
-
current = current.then(function () {
|
209
|
-
return needle.getAsync(URL, options);
|
210
|
-
});
|
211
|
-
return current;
|
212
|
-
}).map(function(responseAndBody){
|
213
|
-
return JSON.parse(responseAndBody[1]);
|
214
|
-
}).then(function (results) {
|
215
|
-
return processAndSaveAllInDB(results);
|
216
|
-
}).then(function(){
|
217
|
-
console.log('All Needle requests saved');
|
218
|
-
}).catch(function (e) {
|
219
|
-
console.log(e);
|
220
|
-
});
|
221
|
-
```
|
222
|
-
|
223
|
-
Also promises don't just give you correspondences for synchronous features but can also be used as limited event emitters or callback aggregators.
|
224
|
-
|
225
|
-
More reading:
|
226
|
-
|
227
|
-
- [Promise nuggets](https://promise-nuggets.github.io/)
|
228
|
-
- [Why I am switching to promises](http://spion.github.io/posts/why-i-am-switching-to-promises.html)
|
229
|
-
- [What is the the point of promises](http://domenic.me/2012/10/14/youre-missing-the-point-of-promises/#toc_1)
|
230
|
-
- [Snippets for common problems](https://github.com/petkaantonov/bluebird/wiki/Snippets)
|
231
|
-
- [Promise anti-patterns](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns)
|
232
|
-
|
233
|
-
# Questions and issues
|
234
|
-
|
235
|
-
The [github issue tracker](https://github.com/petkaantonov/bluebird/issues) is **_only_** for bug reports and feature requests. Anything else, such as questions for help in using the library, should be posted in [StackOverflow](http://stackoverflow.com/questions/tagged/bluebird) under tags `promise` and `bluebird`.
|
236
|
-
|
237
|
-
# Error handling
|
238
|
-
|
239
|
-
This is a problem every promise library needs to handle in some way. Unhandled rejections/exceptions don't really have a good agreed-on asynchronous correspondence. The problem is that it is impossible to predict the future and know if a rejected promise will eventually be handled.
|
240
|
-
|
241
|
-
There are two common pragmatic attempts at solving the problem that promise libraries do.
|
242
|
-
|
243
|
-
The more popular one is to have the user explicitly communicate that they are done and any unhandled rejections should be thrown, like so:
|
244
|
-
|
245
|
-
```js
|
246
|
-
download().then(...).then(...).done();
|
247
|
-
```
|
248
|
-
|
249
|
-
For handling this problem, in my opinion, this is completely unacceptable and pointless. The user must remember to explicitly call `.done` and that cannot be justified when the problem is forgetting to create an error handler in the first place.
|
250
|
-
|
251
|
-
The second approach, which is what bluebird by default takes, is to call a registered handler if a rejection is unhandled by the start of a second turn. The default handler is to write the stack trace to `stderr` or `console.error` in browsers. This is close to what happens with synchronous code - your code doesn't work as expected and you open console and see a stack trace. Nice.
|
252
|
-
|
253
|
-
Of course this is not perfect, if your code for some reason needs to swoop in and attach error handler to some promise after the promise has been hanging around a while then you will see annoying messages. In that case you can use the `.done()` method to signal that any hanging exceptions should be thrown.
|
254
|
-
|
255
|
-
If you want to override the default handler for these possibly unhandled rejections, you can pass yours like so:
|
256
|
-
|
257
|
-
```js
|
258
|
-
Promise.onPossiblyUnhandledRejection(function(error){
|
259
|
-
throw error;
|
260
|
-
});
|
261
|
-
```
|
262
|
-
|
263
|
-
If you want to also enable long stack traces, call:
|
264
|
-
|
265
|
-
```js
|
266
|
-
Promise.longStackTraces();
|
267
|
-
```
|
268
|
-
|
269
|
-
right after the library is loaded.
|
270
|
-
|
271
|
-
In node.js use the environment flag `BLUEBIRD_DEBUG`:
|
272
|
-
|
273
|
-
```
|
274
|
-
BLUEBIRD_DEBUG=1 node server.js
|
275
|
-
```
|
276
|
-
|
277
|
-
to enable long stack traces in all instances of bluebird.
|
278
|
-
|
279
|
-
Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have already been created. Long stack traces imply a substantial performance penalty, even after using every trick to optimize them.
|
280
|
-
|
281
|
-
Long stack traces are enabled by default in the debug build.
|
282
|
-
|
283
|
-
#### Expected and unexpected errors
|
284
|
-
|
285
|
-
A practical problem with Promises/A+ is that it models Javascript `try-catch` too closely for its own good. Therefore by default promises inherit `try-catch` warts such as the inability to specify the error types that the catch block is eligible for. It is an anti-pattern in every other language to use catch-all handlers because they swallow exceptions that you might not know about.
|
286
|
-
|
287
|
-
Now, Javascript does have a perfectly fine and working way of creating error type hierarchies. It is still quite awkward to use them with the built-in `try-catch` however:
|
288
|
-
|
289
|
-
```js
|
290
|
-
try {
|
291
|
-
//code
|
292
|
-
}
|
293
|
-
catch(e) {
|
294
|
-
if( e instanceof WhatIWantError) {
|
295
|
-
//handle
|
296
|
-
}
|
297
|
-
else {
|
298
|
-
throw e;
|
299
|
-
}
|
300
|
-
}
|
301
|
-
```
|
302
|
-
|
303
|
-
Without such checking, unexpected errors would be silently swallowed. However, with promises, bluebird brings the future (hopefully) here now and extends the `.catch` to [accept potential error type eligibility](API.md#catchfunction-errorclass-function-handler---promise).
|
304
|
-
|
305
|
-
For instance here it is expected that some evil or incompetent entity will try to crash our server from `SyntaxError` by providing syntactically invalid JSON:
|
306
|
-
|
307
|
-
```js
|
308
|
-
getJSONFromSomewhere().then(function(jsonString) {
|
309
|
-
return JSON.parse(jsonString);
|
310
|
-
}).then(function(object) {
|
311
|
-
console.log("it was valid json: ", object);
|
312
|
-
}).catch(SyntaxError, function(e){
|
313
|
-
console.log("don't be evil");
|
314
|
-
});
|
315
|
-
```
|
316
|
-
|
317
|
-
Here any kind of unexpected error will be automatically reported on `stderr` along with a stack trace because we only register a handler for the expected `SyntaxError`.
|
318
|
-
|
319
|
-
Ok, so, that's pretty neat. But actually not many libraries define error types and it is in fact a complete ghetto out there with ad hoc strings being attached as some arbitrary property name like `.name`, `.type`, `.code`, not having any property at all or even throwing strings as errors and so on. So how can we still listen for expected errors?
|
320
|
-
|
321
|
-
Bluebird defines a special error type `OperationalError` (you can get a reference from `Promise.OperationalError`). This type of error is given as rejection reason by promisified methods when
|
322
|
-
their underlying library gives an untyped, but expected error. Primitives such as strings, and error objects that are directly created like `new Error("database didn't respond")` are considered untyped.
|
323
|
-
|
324
|
-
Example of such library is the node core library `fs`. So if we promisify it, we can catch just the errors we want pretty easily and have programmer errors be redirected to unhandled rejection handler so that we notice them:
|
325
|
-
|
326
|
-
```js
|
327
|
-
//Read more about promisification in the API Reference:
|
328
|
-
//API.md
|
329
|
-
var fs = Promise.promisifyAll(require("fs"));
|
330
|
-
|
331
|
-
fs.readFileAsync("myfile.json").then(JSON.parse).then(function (json) {
|
332
|
-
console.log("Successful json");
|
333
|
-
}).catch(SyntaxError, function (e) {
|
334
|
-
console.error("file contains invalid json");
|
335
|
-
}).catch(Promise.OperationalError, function (e) {
|
336
|
-
console.error("unable to read file, because: ", e.message);
|
337
|
-
});
|
338
|
-
```
|
339
|
-
|
340
|
-
The last `catch` handler is only invoked when the `fs` module explicitly used the `err` argument convention of async callbacks to inform of an expected error. The `OperationalError` instance will contain the original error in its `.cause` property but it does have a direct copy of the `.message` and `.stack` too. In this code any unexpected error - be it in our code or the `fs` module - would not be caught by these handlers and therefore not swallowed.
|
341
|
-
|
342
|
-
Since a `catch` handler typed to `Promise.OperationalError` is expected to be used very often, it has a neat shorthand:
|
343
|
-
|
344
|
-
```js
|
345
|
-
.error(function (e) {
|
346
|
-
console.error("unable to read file, because: ", e.message);
|
347
|
-
});
|
348
|
-
```
|
349
|
-
|
350
|
-
See [API documentation for `.error()`](API.md#error-rejectedhandler----promise)
|
351
|
-
|
352
|
-
Finally, Bluebird also supports predicate-based filters. If you pass a
|
353
|
-
predicate function instead of an error type, the predicate will receive
|
354
|
-
the error as an argument. The return result will be used to determine whether
|
355
|
-
the error handler should be called.
|
356
|
-
|
357
|
-
Predicates should allow for very fine grained control over caught errors:
|
358
|
-
pattern matching, error typesets with set operations and many other techniques
|
359
|
-
can be implemented on top of them.
|
360
|
-
|
361
|
-
Example of using a predicate-based filter:
|
362
|
-
|
363
|
-
```js
|
364
|
-
var Promise = require("bluebird");
|
365
|
-
var request = Promise.promisify(require("request"));
|
366
|
-
|
367
|
-
function clientError(e) {
|
368
|
-
return e.code >= 400 && e.code < 500;
|
369
|
-
}
|
370
|
-
|
371
|
-
request("http://www.google.com").then(function(contents){
|
372
|
-
console.log(contents);
|
373
|
-
}).catch(clientError, function(e){
|
374
|
-
//A client error like 400 Bad Request happened
|
375
|
-
});
|
376
|
-
```
|
377
|
-
|
378
|
-
**Danger:** The JavaScript language allows throwing primitive values like strings. Throwing primitives can lead to worse or no stack traces. Primitives [are not exceptions](http://www.devthought.com/2011/12/22/a-string-is-not-an-error/). You should consider always throwing Error objects when handling exceptions.
|
379
|
-
|
380
|
-
<hr>
|
381
|
-
|
382
|
-
#### How do long stack traces differ from e.g. Q?
|
383
|
-
|
384
|
-
Bluebird attempts to have more elaborate traces. Consider:
|
385
|
-
|
386
|
-
```js
|
387
|
-
Error.stackTraceLimit = 25;
|
388
|
-
Q.longStackSupport = true;
|
389
|
-
Q().then(function outer() {
|
390
|
-
return Q().then(function inner() {
|
391
|
-
return Q().then(function evenMoreInner() {
|
392
|
-
a.b.c.d();
|
393
|
-
}).catch(function catcher(e){
|
394
|
-
console.error(e.stack);
|
395
|
-
});
|
396
|
-
})
|
397
|
-
});
|
398
|
-
```
|
399
|
-
|
400
|
-
You will see
|
401
|
-
|
402
|
-
ReferenceError: a is not defined
|
403
|
-
at evenMoreInner (<anonymous>:7:13)
|
404
|
-
From previous event:
|
405
|
-
at inner (<anonymous>:6:20)
|
406
|
-
|
407
|
-
Compare to:
|
408
|
-
|
409
|
-
```js
|
410
|
-
Error.stackTraceLimit = 25;
|
411
|
-
Promise.longStackTraces();
|
412
|
-
Promise.resolve().then(function outer() {
|
413
|
-
return Promise.resolve().then(function inner() {
|
414
|
-
return Promise.resolve().then(function evenMoreInner() {
|
415
|
-
a.b.c.d();
|
416
|
-
}).catch(function catcher(e){
|
417
|
-
console.error(e.stack);
|
418
|
-
});
|
419
|
-
});
|
420
|
-
});
|
421
|
-
```
|
422
|
-
|
423
|
-
ReferenceError: a is not defined
|
424
|
-
at evenMoreInner (<anonymous>:7:13)
|
425
|
-
From previous event:
|
426
|
-
at inner (<anonymous>:6:36)
|
427
|
-
From previous event:
|
428
|
-
at outer (<anonymous>:5:32)
|
429
|
-
From previous event:
|
430
|
-
at <anonymous>:4:21
|
431
|
-
at Object.InjectedScript._evaluateOn (<anonymous>:572:39)
|
432
|
-
at Object.InjectedScript._evaluateAndWrap (<anonymous>:531:52)
|
433
|
-
at Object.InjectedScript.evaluate (<anonymous>:450:21)
|
434
|
-
|
435
|
-
|
436
|
-
A better and more practical example of the differences can be seen in gorgikosev's [debuggability competition](https://github.com/spion/async-compare#debuggability).
|
437
|
-
|
438
|
-
<hr>
|
439
|
-
|
440
|
-
# Development
|
441
|
-
|
442
|
-
For development tasks such as running benchmarks or testing, you need to clone the repository and install dev-dependencies.
|
443
|
-
|
444
|
-
Install [node](http://nodejs.org/) and [npm](https://npmjs.org/)
|
445
|
-
|
446
|
-
git clone git@github.com:petkaantonov/bluebird.git
|
447
|
-
cd bluebird
|
448
|
-
npm install
|
449
|
-
|
450
|
-
## Testing
|
451
|
-
|
452
|
-
To run all tests, run
|
453
|
-
|
454
|
-
node tools/test
|
455
|
-
|
456
|
-
If you need to run generator tests run the `tool/test.js` script with `--harmony` argument and node 0.11+:
|
457
|
-
|
458
|
-
node-dev --harmony tools/test
|
459
|
-
|
460
|
-
You may specify an individual test file to run with the `--run` script flag:
|
461
|
-
|
462
|
-
node tools/test --run=cancel.js
|
463
|
-
|
464
|
-
|
465
|
-
This enables output from the test and may give a better idea where the test is failing. The parameter to `--run` can be any file name located in `test/mocha` folder.
|
466
|
-
|
467
|
-
#### Testing in browsers
|
468
|
-
|
469
|
-
To run the test in a browser instead of node, pass the flag `--browser` to the test tool
|
470
|
-
|
471
|
-
node tools/test --run=cancel.js --browser
|
472
|
-
|
473
|
-
This will automatically create a server (default port 9999) and open it in your default browser once the tests have been compiled.
|
474
|
-
|
475
|
-
Keep the test tab active because some tests are timing-sensitive and will fail if the browser is throttling timeouts. Chrome will do this for example when the tab is not active.
|
476
|
-
|
477
|
-
#### Supported options by the test tool
|
478
|
-
|
479
|
-
The value of boolean flags is determined by presence, if you want to pass false value for a boolean flag, use the `no-`-prefix e.g. `--no-browser`.
|
480
|
-
|
481
|
-
- `--run=String` - Which tests to run (or compile when testing in browser). Default `"all"`. Can also be a glob string (relative to ./test/mocha folder).
|
482
|
-
- `--cover=String`. Create code coverage using the String as istanbul reporter. Coverage is created in the ./coverage folder. No coverage is created by default, default reporter is `"html"` (use `--cover` to use default reporter).
|
483
|
-
- `--browser` - Whether to compile tests for browsers. Default `false`.
|
484
|
-
- `--port=Number` - Port where local server is hosted when testing in browser. Default `9999`
|
485
|
-
- `--execute-browser-tests` - Whether to execute the compiled tests for browser when using `--browser`. Default `true`.
|
486
|
-
- `--open-browser` - Whether to open the default browser when executing browser tests. Default `true`.
|
487
|
-
- `--fake-timers` - Whether to use fake timers (`setTimeout` etc) when running tests in node. Default `true`.
|
488
|
-
- `--js-hint` - Whether to run JSHint on source files. Default `true`.
|
489
|
-
- `--saucelabs` - Whether to create a tunnel to sauce labs and run tests in their VMs instead of your browser when compiling tests for browser. Default `false`.
|
490
|
-
|
491
|
-
## Benchmarks
|
492
|
-
|
493
|
-
To run a benchmark, run the given command for a benchmark while on the project root. Requires bash (on windows the mingw32 that comes with git works fine too).
|
494
|
-
|
495
|
-
Node 0.11.2+ is required to run the generator examples.
|
496
|
-
|
497
|
-
### 1\. DoxBee sequential
|
498
|
-
|
499
|
-
Currently the most relevant benchmark is @gorkikosev's benchmark in the article [Analysis of generators and other async patterns in node](http://spion.github.io/posts/analysis-generators-and-other-async-patterns-node.html). The benchmark emulates a situation where n amount of users are making a request in parallel to execute some mixed async/sync action. The benchmark has been modified to include a warm-up phase to minimize any JITing during timed sections.
|
500
|
-
|
501
|
-
Command: `bench doxbee`
|
502
|
-
|
503
|
-
### 2\. Made-up parallel
|
504
|
-
|
505
|
-
This made-up scenario runs 15 shimmed queries in parallel.
|
506
|
-
|
507
|
-
Command: `bench parallel`
|
508
|
-
|
509
|
-
## Custom builds
|
510
|
-
|
511
|
-
Custom builds for browsers are supported through a command-line utility.
|
512
|
-
|
513
|
-
|
514
|
-
<table>
|
515
|
-
<caption>The following features can be disabled</caption>
|
516
|
-
<thead>
|
517
|
-
<tr>
|
518
|
-
<th>Feature(s)</th>
|
519
|
-
<th>Command line identifier</th>
|
520
|
-
</tr>
|
521
|
-
</thead>
|
522
|
-
<tbody>
|
523
|
-
|
524
|
-
<tr><td><a href="API.md#any---promise"><code>.any</code></a> and <a href="API.md#promiseanyarraydynamicpromise-values---promise"><code>Promise.any</code></a></td><td><code>any</code></td></tr>
|
525
|
-
<tr><td><a href="API.md#race---promise"><code>.race</code></a> and <a href="API.md#promiseracearraypromise-promises---promise"><code>Promise.race</code></a></td><td><code>race</code></td></tr>
|
526
|
-
<tr><td><a href="API.md#callstring-propertyname--dynamic-arg---promise"><code>.call</code></a> and <a href="API.md#getstring-propertyname---promise"><code>.get</code></a></td><td><code>call_get</code></td></tr>
|
527
|
-
<tr><td><a href="API.md#filterfunction-filterer---promise"><code>.filter</code></a> and <a href="API.md#promisefilterarraydynamicpromise-values-function-filterer---promise"><code>Promise.filter</code></a></td><td><code>filter</code></td></tr>
|
528
|
-
<tr><td><a href="API.md#mapfunction-mapper---promise"><code>.map</code></a> and <a href="API.md#promisemaparraydynamicpromise-values-function-mapper---promise"><code>Promise.map</code></a></td><td><code>map</code></td></tr>
|
529
|
-
<tr><td><a href="API.md#reducefunction-reducer--dynamic-initialvalue---promise"><code>.reduce</code></a> and <a href="API.md#promisereducearraydynamicpromise-values-function-reducer--dynamic-initialvalue---promise"><code>Promise.reduce</code></a></td><td><code>reduce</code></td></tr>
|
530
|
-
<tr><td><a href="API.md#props---promise"><code>.props</code></a> and <a href="API.md#promisepropsobjectpromise-object---promise"><code>Promise.props</code></a></td><td><code>props</code></td></tr>
|
531
|
-
<tr><td><a href="API.md#settle---promise"><code>.settle</code></a> and <a href="API.md#promisesettlearraydynamicpromise-values---promise"><code>Promise.settle</code></a></td><td><code>settle</code></td></tr>
|
532
|
-
<tr><td><a href="API.md#someint-count---promise"><code>.some</code></a> and <a href="API.md#promisesomearraydynamicpromise-values-int-count---promise"><code>Promise.some</code></a></td><td><code>some</code></td></tr>
|
533
|
-
<tr><td><a href="API.md#nodeifyfunction-callback---promise"><code>.nodeify</code></a></td><td><code>nodeify</code></td></tr>
|
534
|
-
<tr><td><a href="API.md#promisecoroutinegeneratorfunction-generatorfunction---function"><code>Promise.coroutine</code></a> and <a href="API.md#promisespawngeneratorfunction-generatorfunction---promise"><code>Promise.spawn</code></a></td><td><code>generators</code></td></tr>
|
535
|
-
<tr><td><a href="API.md#progression">Progression</a></td><td><code>progress</code></td></tr>
|
536
|
-
<tr><td><a href="API.md#promisification">Promisification</a></td><td><code>promisify</code></td></tr>
|
537
|
-
<tr><td><a href="API.md#cancellation">Cancellation</a></td><td><code>cancel</code></td></tr>
|
538
|
-
<tr><td><a href="API.md#timers">Timers</a></td><td><code>timers</code></td></tr>
|
539
|
-
<tr><td><a href="API.md#resource-management">Resource management</a></td><td><code>using</code></td></tr>
|
540
|
-
|
541
|
-
</tbody>
|
542
|
-
</table>
|
543
|
-
|
544
|
-
|
545
|
-
Make sure you have cloned the repo somewhere and did `npm install` successfully.
|
546
|
-
|
547
|
-
After that you can run:
|
548
|
-
|
549
|
-
node tools/build --features="core"
|
550
|
-
|
551
|
-
|
552
|
-
The above builds the most minimal build you can get. You can add more features separated by spaces from the above list:
|
553
|
-
|
554
|
-
node tools/build --features="core filter map reduce"
|
555
|
-
|
556
|
-
The custom build file will be found from `/js/browser/bluebird.js`. It will have a comment that lists the disabled and enabled features.
|
557
|
-
|
558
|
-
Note that the build leaves the `/js/main` etc folders with same features so if you use the folder for node.js at the same time, don't forget to build
|
559
|
-
a full version afterwards (after having taken a copy of the bluebird.js somewhere):
|
560
|
-
|
561
|
-
node tools/build --debug --main --zalgo --browser --minify
|
562
|
-
|
563
|
-
#### Supported options by the build tool
|
564
|
-
|
565
|
-
The value of boolean flags is determined by presence, if you want to pass false value for a boolean flag, use the `no-`-prefix e.g. `--no-debug`.
|
566
|
-
|
567
|
-
- `--main` - Whether to build the main build. The main build is placed at `js/main` directory. Default `false`.
|
568
|
-
- `--debug` - Whether to build the debug build. The debug build is placed at `js/debug` directory. Default `false`.
|
569
|
-
- `--zalgo` - Whether to build the zalgo build. The zalgo build is placed at `js/zalgo` directory. Default `false`.
|
570
|
-
- `--browser` - Whether to compile the browser build. The browser build file is placed at `js/browser/bluebird.js` Default `false`.
|
571
|
-
- `--minify` - Whether to minify the compiled browser build. The minified browser build file is placed at `js/browser/bluebird.min.js` Default `true`.
|
572
|
-
- `--features=String` - See [custom builds](#custom-builds)
|
573
|
-
|
574
|
-
<hr>
|
575
|
-
|
576
|
-
## For library authors
|
577
|
-
|
578
|
-
Building a library that depends on bluebird? You should know about a few features.
|
579
|
-
|
580
|
-
If your library needs to do something obtrusive like adding or modifying methods on the `Promise` prototype, uses long stack traces or uses a custom unhandled rejection handler then... that's totally ok as long as you don't use `require("bluebird")`. Instead you should create a file
|
581
|
-
that creates an isolated copy. For example, creating a file called `bluebird-extended.js` that contains:
|
582
|
-
|
583
|
-
```js
|
584
|
-
//NOTE the function call right after
|
585
|
-
module.exports = require("bluebird/js/main/promise")();
|
586
|
-
```
|
587
|
-
|
588
|
-
Your library can then use `var Promise = require("bluebird-extended");` and do whatever it wants with it. Then if the application or other library uses their own bluebird promises they will all play well together because of Promises/A+ thenable assimilation magic.
|
589
|
-
|
590
|
-
You should also know about [`.nodeify()`](API.md#nodeifyfunction-callback---promise) which makes it easy to provide a dual callback/promise API.
|
591
|
-
|
592
|
-
<hr>
|
593
|
-
|
594
|
-
## What is the sync build?
|
595
|
-
|
596
|
-
You may now use sync build by:
|
597
|
-
|
598
|
-
var Promise = require("bluebird/zalgo");
|
599
|
-
|
600
|
-
The sync build is provided to see how forced asynchronity affects benchmarks. It should not be used in real code due to the implied hazards.
|
601
|
-
|
602
|
-
The normal async build gives Promises/A+ guarantees about asynchronous resolution of promises. Some people think this affects performance or just plain love their code having a possibility
|
603
|
-
of stack overflow errors and non-deterministic behavior.
|
604
|
-
|
605
|
-
The sync build skips the async call trampoline completely, e.g code like:
|
606
|
-
|
607
|
-
async.invoke( this.fn, this, val );
|
608
|
-
|
609
|
-
Appears as this in the sync build:
|
610
|
-
|
611
|
-
this.fn(val);
|
612
|
-
|
613
|
-
This should pressure the CPU slightly less and thus the sync build should perform better. Indeed it does, but only marginally. The biggest performance boosts are from writing efficient Javascript, not from compromising determinism.
|
614
|
-
|
615
|
-
Note that while some benchmarks are waiting for the next event tick, the CPU is actually not in use during that time. So the resulting benchmark result is not completely accurate because on node.js you only care about how much the CPU is taxed. Any time spent on CPU is time the whole process (or server) is paralyzed. And it is not graceful like it would be with threads.
|
616
|
-
|
617
|
-
|
618
|
-
```js
|
619
|
-
var cache = new Map(); //ES6 Map or DataStructures/Map or whatever...
|
620
|
-
function getResult(url) {
|
621
|
-
var resolver = Promise.pending();
|
622
|
-
if (cache.has(url)) {
|
623
|
-
resolver.resolve(cache.get(url));
|
624
|
-
}
|
625
|
-
else {
|
626
|
-
http.get(url, function(err, content) {
|
627
|
-
if (err) resolver.reject(err);
|
628
|
-
else {
|
629
|
-
cache.set(url, content);
|
630
|
-
resolver.resolve(content);
|
631
|
-
}
|
632
|
-
});
|
633
|
-
}
|
634
|
-
return resolver.promise;
|
635
|
-
}
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
//The result of console.log is truly random without async guarantees
|
640
|
-
function guessWhatItPrints( url ) {
|
641
|
-
var i = 3;
|
642
|
-
getResult(url).then(function(){
|
643
|
-
i = 4;
|
644
|
-
});
|
645
|
-
console.log(i);
|
646
|
-
}
|
647
|
-
```
|
648
|
-
|
649
|
-
# Optimization guide
|
650
|
-
|
651
|
-
Articles about optimization will be periodically posted in [the wiki section](https://github.com/petkaantonov/bluebird/wiki), polishing edits are welcome.
|
652
|
-
|
653
|
-
A single cohesive guide compiled from the articles will probably be done eventually.
|
654
|
-
|
655
|
-
# License
|
656
|
-
|
657
|
-
The MIT License (MIT)
|
658
|
-
|
659
|
-
Copyright (c) 2015 Petka Antonov
|
660
|
-
|
661
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
662
|
-
of this software and associated documentation files (the "Software"), to deal
|
663
|
-
in the Software without restriction, including without limitation the rights
|
664
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
665
|
-
copies of the Software, and to permit persons to whom the Software is
|
666
|
-
furnished to do so, subject to the following conditions:
|
667
|
-
|
668
|
-
The above copyright notice and this permission notice shall be included in
|
669
|
-
all copies or substantial portions of the Software.
|
670
|
-
|
671
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
672
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
673
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
674
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
675
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
676
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
677
|
-
THE SOFTWARE.
|