Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rsvp.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
rsvp.js
Commits
dd3c1b1f
Commit
dd3c1b1f
authored
Oct 09, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queue should respect promise A+.
parent
5ccaf0c5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
12 deletions
+102
-12
lib/rsvp/queue.js
lib/rsvp/queue.js
+39
-10
options/mocha_test.js
options/mocha_test.js
+10
-0
test/test-queue-adapter.js
test/test-queue-adapter.js
+51
-0
test/tests/extension_test.js
test/tests/extension_test.js
+2
-2
No files found.
lib/rsvp/queue.js
View file @
dd3c1b1f
...
@@ -13,10 +13,12 @@ ResolvedQueueError.prototype = new Error();
...
@@ -13,10 +13,12 @@ ResolvedQueueError.prototype = new Error();
ResolvedQueueError
.
prototype
.
constructor
=
ResolvedQueueError
;
ResolvedQueueError
.
prototype
.
constructor
=
ResolvedQueueError
;
var
Queue
=
function
()
{
var
Queue
=
function
()
{
var
promis
e
=
this
,
var
queu
e
=
this
,
promise_list
=
[],
promise_list
=
[],
promise
,
fulfill
,
fulfill
,
reject
;
reject
,
resolved
;
if
(
!
(
this
instanceof
Queue
))
{
if
(
!
(
this
instanceof
Queue
))
{
return
new
Queue
();
return
new
Queue
();
...
@@ -28,10 +30,22 @@ var Queue = function() {
...
@@ -28,10 +30,22 @@ var Queue = function() {
}
}
}
}
Promise
.
apply
(
promise
,
[
function
(
done
,
fail
)
{
promise
=
new
Promise
(
function
(
done
,
fail
)
{
fulfill
=
done
;
fulfill
=
function
(
fulfillmentValue
)
{
reject
=
fail
;
if
(
resolved
)
{
return
;}
},
canceller
]);
queue
.
isFulfilled
=
true
;
queue
.
fulfillmentValue
=
fulfillmentValue
;
resolved
=
true
;
return
done
(
fulfillmentValue
);
};
reject
=
function
(
rejectedReason
)
{
if
(
resolved
)
{
return
;}
queue
.
isRejected
=
true
;
queue
.
rejectedReason
=
rejectedReason
;
resolved
=
true
;
return
fail
(
rejectedReason
);
};
},
canceller
);
promise_list
.
push
(
delay
());
promise_list
.
push
(
delay
());
promise_list
.
push
(
promise_list
[
0
].
then
(
function
()
{
promise_list
.
push
(
promise_list
[
0
].
then
(
function
()
{
...
@@ -41,11 +55,24 @@ var Queue = function() {
...
@@ -41,11 +55,24 @@ var Queue = function() {
}
}
}));
}));
promise
.
push
=
function
(
done
,
fail
)
{
queue
.
cancel
=
function
()
{
if
(
resolved
)
{
return
;}
resolved
=
true
;
promise
.
cancel
();
promise
.
fail
(
function
(
rejectedReason
)
{
queue
.
isRejected
=
true
;
queue
.
rejectedReason
=
rejectedReason
;
});
};
queue
.
then
=
function
()
{
return
promise
.
then
.
apply
(
promise
,
arguments
);
};
queue
.
push
=
function
(
done
,
fail
)
{
var
last_promise
=
promise_list
[
promise_list
.
length
-
1
],
var
last_promise
=
promise_list
[
promise_list
.
length
-
1
],
next_promise
;
next_promise
;
if
(
this
.
isRejected
||
this
.
isFulfill
ed
)
{
if
(
resolv
ed
)
{
throw
new
ResolvedQueueError
();
throw
new
ResolvedQueueError
();
}
}
...
@@ -61,10 +88,12 @@ var Queue = function() {
...
@@ -61,10 +88,12 @@ var Queue = function() {
return
fulfillmentValue
;
return
fulfillmentValue
;
}
}
},
function
(
rejectedReason
)
{
},
function
(
rejectedReason
)
{
if
(
!
(
promise
.
isRejected
||
promise
.
isFulfilled
))
{
promise_list
.
splice
(
0
,
2
);
if
(
promise_list
.
length
===
0
)
{
reject
(
rejectedReason
);
reject
(
rejectedReason
);
}
else
{
throw
rejectedReason
;
}
}
throw
rejectedReason
;
}));
}));
return
this
;
return
this
;
...
...
options/mocha_test.js
View file @
dd3c1b1f
...
@@ -9,5 +9,15 @@ module.exports = {
...
@@ -9,5 +9,15 @@ module.exports = {
options
:
{
options
:
{
reporter
:
'
spec
'
reporter
:
'
spec
'
}
}
// },
// test2: {
// src: [
// 'test/vendor/assert.js',
// 'test/test-queue-adapter.js',
// 'node_modules/promises-aplus-tests/lib/tests/**/*.js'
// ],
// options: {
// reporter: 'spec'
// }
}
}
};
};
test/test-queue-adapter.js
0 → 100644
View file @
dd3c1b1f
/*global RSVP*/
var
Queue
;
if
(
typeof
RSVP
!==
'
undefined
'
)
{
// Test the browser build
Queue
=
RSVP
.
Queue
;
}
else
{
// Test the Node build
RSVP
=
require
(
'
../dist/commonjs/main
'
);
Queue
=
require
(
'
../dist/commonjs/main
'
).
Queue
;
Promise
=
require
(
'
../dist/commonjs/main
'
).
Promise
;
assert
=
require
(
'
./vendor/assert
'
);
}
if
(
typeof
window
===
'
undefined
'
&&
typeof
global
!==
'
undefined
'
)
{
window
=
global
;
}
var
adapter
=
{};
adapter
.
fulfilled
=
function
(
value
)
{
return
new
Queue
()
.
push
(
function
()
{
return
value
;
});
};
adapter
.
rejected
=
function
(
error
)
{
return
new
Queue
()
.
push
(
function
()
{
return
RSVP
.
reject
(
error
);
});
};
adapter
.
pending
=
function
()
{
var
pending
=
{},
promise
=
new
Promise
(
function
(
resolve
,
reject
)
{
pending
.
fulfill
=
resolve
;
pending
.
reject
=
reject
;
});
pending
.
promise
=
new
Queue
()
.
push
(
function
()
{
return
promise
;
});
return
pending
;
};
module
.
exports
=
global
.
adapter
=
adapter
;
test/tests/extension_test.js
View file @
dd3c1b1f
...
@@ -2331,7 +2331,7 @@ describe("`RSVP.Queue`", function () {
...
@@ -2331,7 +2331,7 @@ describe("`RSVP.Queue`", function () {
});
});
queue
.
push
(
undefined
,
function
(
value
)
{
queue
.
push
(
undefined
,
function
(
value
)
{
pushed_result
=
value
;
pushed_result
=
value
;
return
"
bar
"
;
throw
value
;
});
});
setTimeout
(
function
()
{
setTimeout
(
function
()
{
...
@@ -2350,7 +2350,7 @@ describe("`RSVP.Queue`", function () {
...
@@ -2350,7 +2350,7 @@ describe("`RSVP.Queue`", function () {
});
});
queue
.
push
(
undefined
,
function
(
value
)
{
queue
.
push
(
undefined
,
function
(
value
)
{
pushed_result
=
value
;
pushed_result
=
value
;
return
"
bar
"
;
throw
value
;
});
});
queue
.
cancel
();
queue
.
cancel
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment