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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
rsvp.js
Commits
974b8596
Commit
974b8596
authored
Sep 25, 2018
by
Romain Courteaud
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce number of array
parent
e410c7ce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
26 deletions
+18
-26
lib/rsvp/queue.js
lib/rsvp/queue.js
+18
-26
No files found.
lib/rsvp/queue.js
View file @
974b8596
...
...
@@ -12,39 +12,30 @@ function ResolvedQueueError(message) {
ResolvedQueueError
.
prototype
=
new
Error
();
ResolvedQueueError
.
prototype
.
constructor
=
ResolvedQueueError
;
var
last_promise
,
i
;
var
Queue
=
function
()
{
if
(
!
(
this
instanceof
Queue
))
{
return
new
Queue
();
}
var
queue
=
this
,
promise_stack
=
[],
then_stack
=
[]
;
var
promise_stack
=
[]
,
// handleQueue
detect_end_index
=
1
;
Promise
.
call
(
queue
,
function
(
resolveQueue
,
rejectQueue
)
{
Promise
.
call
(
this
,
function
(
resolveQueue
,
rejectQueue
)
{
var
detectQueueSuccess
,
detectQueueError
;
function
handleQueue
()
{
if
(
then_stack
.
length
===
0
)
{
if
(
promise_stack
.
length
===
detect_end_index
)
{
return
true
;
}
last_promise
=
promise_stack
[
promise_stack
.
length
-
1
];
promise_stack
.
splice
(
0
,
promise_stack
.
length
);
for
(
i
=
then_stack
.
length
-
1
;
i
>=
0
;
i
-=
2
)
{
last_promise
=
last_promise
.
then
(
then_stack
[
i
-
1
],
then_stack
[
i
]);
promise_stack
.
push
(
last_promise
);
}
then_stack
.
splice
(
0
,
then_stack
.
length
);
promise_stack
.
splice
(
0
,
detect_end_index
);
promise_stack
.
push
(
last_promise
.
then
(
detectQueueSuccess
,
promise_stack
[
promise_stack
.
length
-
1
]
.
then
(
detectQueueSuccess
,
detectQueueError
)
);
detect_end_index
=
promise_stack
.
length
;
return
false
;
}
...
...
@@ -64,28 +55,29 @@ var Queue = function() {
// Resolve by default
promise_stack
.
push
(
resolve
().
then
(
detectQueueSuccess
,
detectQueueError
)
resolve
().
then
(
detectQueueSuccess
)
);
},
function
()
{
// Cancel all created promises
var
i
;
then_stack
.
splice
(
0
,
then_stack
.
length
);
for
(
i
=
0
;
i
<
promise_stack
.
length
;
i
+=
1
)
{
promise_stack
[
i
].
cancel
();
}
});
queue
.
push
=
function
(
done
,
fail
)
{
if
(
queue
.
isFulfilled
||
queue
.
isRejected
)
{
this
.
push
=
function
(
done
,
fail
)
{
if
(
this
.
isFulfilled
||
this
.
isRejected
)
{
throw
new
ResolvedQueueError
();
}
then_stack
.
unshift
(
done
,
fail
);
return
queue
;
promise_stack
.
push
(
promise_stack
[
promise_stack
.
length
-
1
].
then
(
done
,
fail
)
);
return
this
;
};
return
queue
;
return
this
;
};
Queue
.
prototype
=
Object
.
create
(
Promise
.
prototype
);
...
...
Romain Courteaud
@romain
mentioned in commit
89646829
·
Feb 25, 2020
mentioned in commit
89646829
mentioned in commit 89646829f7a5f55e04e717ed841e2711de13ad1e
Toggle commit list
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