Skip to content

Commit

Permalink
rethrow (rsvp => promise)
Browse files Browse the repository at this point in the history
  • Loading branch information
bekzod committed May 21, 2018
1 parent 7802ae4 commit e581248
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 282 deletions.
3 changes: 0 additions & 3 deletions lib/rsvp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Promise from './rsvp/promise';
import EventTarget from './rsvp/events';
import rethrow from './rsvp/rethrow';
import {
config,
configure
Expand Down Expand Up @@ -38,7 +37,6 @@ export default {
asap,
Promise,
EventTarget,
rethrow,
configure,
on,
off,
Expand All @@ -49,7 +47,6 @@ export {
asap,
Promise,
EventTarget,
rethrow,
configure,
on,
off,
Expand Down
2 changes: 2 additions & 0 deletions lib/rsvp/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Defer from './promise/defer';
import AllSettled from './promise/all-settled';
import HashSettled from './promise/hash-settled';
import Filter from './promise/filter';
import Rethrow from './promise/rethrow';
import Resolve from './promise/resolve';
import Reject from './promise/reject';

Expand Down Expand Up @@ -250,6 +251,7 @@ Promise.resolve = Resolve;
Promise.reject = Reject;
Promise.defer = Defer;
Promise.denodeify = Denodeify;
Promise.rethrow = Rethrow;

Promise.prototype._guidKey = guidKey;

Expand Down
4 changes: 2 additions & 2 deletions lib/rsvp/promise/all-settled.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
default as Enumerator,
setSettledResult
} from './enumerator';
import Promise from './promise';
} from '../enumerator';
import Promise from '../promise';

class AllSettled extends Enumerator {
constructor(Constructor, entries, label) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rsvp/promise/filter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Promise from './promise';
import Promise from '../promise';
import { MapEnumerator } from './map';
import {
tryCatch,
fulfill,
TRY_CATCH_ERROR,
REJECTED
} from './-internal';
} from '../-internal';

const EMPTY_OBJECT = {};

Expand Down
4 changes: 2 additions & 2 deletions lib/rsvp/promise/hash-settled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import Promise from '../promise';
import {
default as Enumerator,
setSettledResult
} from './enumerator';
import PromiseHash from './promise-hash';
} from '../enumerator';
import PromiseHash from '../promise-hash';

class HashSettled extends PromiseHash {
constructor(Constructor, object, label) {
Expand Down
6 changes: 3 additions & 3 deletions lib/rsvp/promise/map.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Promise from './promise';
import Promise from '../promise';
import {
default as Enumerator
} from './enumerator';
} from '../enumerator';
import {
tryCatch,
TRY_CATCH_ERROR,
REJECTED
} from './-internal';
} from '../-internal';

export class MapEnumerator extends Enumerator {
constructor(Constructor, entries, mapFn, label) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rsvp/promise/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getThen,
tryCatch,
TRY_CATCH_ERROR
} from './-internal';
} from '../-internal';

function makeObject(_, argumentNames) {
let obj = {};
Expand Down
7 changes: 3 additions & 4 deletions lib/rsvp/promise/resolve.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Promise from '../promise';
import {
noop,
resolve as _resolve
} from '../-internal';


/**
`RSVP.Promise.resolve` returns a promise that will become resolved with the
passed `value`. It is shorthand for the following:
Expand Down Expand Up @@ -39,12 +37,13 @@ import {
*/
export default function resolve(object, label) {
/*jshint validthis:true */
let Constructor = this;

if (object && typeof object === 'object' && object.constructor === Promise) {
if (object && typeof object === 'object' && object.constructor === Constructor) {
return object;
}

let promise = new Promise(noop, label);
let promise = new Constructor(noop, label);
_resolve(promise, object);
return promise;
}
6 changes: 3 additions & 3 deletions lib/rsvp/rethrow.js → lib/rsvp/promise/rethrow.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
`RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event
`RSVP.Promise.rethrow` will rethrow an error on the next turn of the JavaScript event
loop in order to aid debugging.
Promises A+ specifies that any exceptions that occur with a promise must be
caught by the promises implementation and bubbled to the last handler. For
this reason, it is recommended that you always specify a second rejection
handler function to `then`. However, `RSVP.rethrow` will throw the exception
handler function to `then`. However, `RSVP.Promise.rethrow` will throw the exception
outside of the promise, so it bubbles up to your console if in the browser,
or domain/cause uncaught exception in Node. `rethrow` will also throw the
error again so the error can be handled by the promise per the spec.
Expand All @@ -19,7 +19,7 @@
throws();
});
promise.catch(RSVP.rethrow).then(function(){
promise.catch(RSVP.Promise.rethrow).then(function(){
// Code here doesn't run because the promise became rejected due to an
// error!
}, function (err){
Expand Down
Loading

0 comments on commit e581248

Please sign in to comment.