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
8dcbf352
Commit
8dcbf352
authored
Apr 19, 2019
by
Romain Courteaud
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experiment other implementations.
Not working with listbox
parent
974b8596
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
46 deletions
+73
-46
lib/rsvp/queue.js
lib/rsvp/queue.js
+73
-46
No files found.
lib/rsvp/queue.js
View file @
8dcbf352
...
...
@@ -17,66 +17,93 @@ var Queue = function() {
return
new
Queue
();
}
var
promise_stack
=
[],
// handleQueue
detect_end_index
=
1
;
var
function_stack
=
[],
resolveQueue
,
rejectQueue
,
queue
=
this
,
current_promise
=
null
,
handleDone
,
handleReject
,
next_function
;
Promise
.
call
(
this
,
function
(
resolveQueue
,
rejectQueue
)
{
var
detectQueueSuccess
,
detectQueueError
;
function
handleQueue
()
{
if
(
promise_stack
.
length
===
detect_end_index
)
{
return
true
;
handleDone
=
function
(
result
)
{
if
(
queue
.
isRejected
)
{
return
;
}
if
(
function_stack
.
length
>
0
)
{
next_function
=
function_stack
.
shift
();
// Remove fail handler
function_stack
.
shift
();
if
(
next_function
===
undefined
)
{
return
handleDone
(
result
);
}
promise_stack
.
splice
(
0
,
detect_end_index
);
promise_stack
.
push
(
promise_stack
[
promise_stack
.
length
-
1
].
then
(
detectQueueSuccess
,
detectQueueError
)
);
detect_end_index
=
promise_stack
.
length
;
return
false
;
try
{
current_promise
=
next_function
.
call
(
null
,
result
);
}
catch
(
e
)
{
return
handleReject
(
e
);
}
if
((
current_promise
!==
undefined
)
&&
(
typeof
current_promise
.
then
===
"
function
"
))
{
current_promise
.
then
(
handleDone
,
handleReject
);
}
else
{
handleDone
(
current_promise
);
}
return
;
}
resolveQueue
(
result
);
};
detectQueueSuccess
=
function
(
fulfillmentValue
)
{
if
(
handleQueue
())
{
return
resolveQueue
(
fulfillmentValue
);
handleReject
=
function
(
error
)
{
if
(
queue
.
isRejected
)
{
return
;
}
if
(
function_stack
.
length
>
0
)
{
// Remove done handler
function_stack
.
shift
();
next_function
=
function_stack
.
shift
();
if
(
next_function
===
undefined
)
{
return
handleReject
(
error
);
}
return
fulfillmentValue
;
};
detectQueueError
=
function
(
rejectedReason
)
{
if
(
handleQueue
())
{
return
rejectQueue
(
rejectedReason
);
try
{
current_promise
=
next_function
.
call
(
null
,
error
);
}
catch
(
e
)
{
return
handleReject
(
e
);
}
throw
rejectedReason
;
};
// Resolve by default
promise_stack
.
push
(
resolve
().
then
(
detectQueueSuccess
)
);
},
function
()
{
// Cancel all created promises
var
i
;
for
(
i
=
0
;
i
<
promise_stack
.
length
;
i
+=
1
)
{
promise_stack
[
i
].
cancel
();
if
((
current_promise
!==
undefined
)
&&
(
typeof
current_promise
.
then
===
"
function
"
))
{
current_promise
.
then
(
handleDone
,
handleReject
);
}
else
{
handleDone
(
current_promise
);
}
return
;
}
}
)
;
rejectQueue
(
error
);
};
this
.
push
=
function
(
done
,
fail
)
{
if
(
this
.
isFulfilled
||
this
.
isRejected
)
{
if
(
this
.
isFulfilled
||
this
.
isRejected
||
this
.
isCancelled
)
{
throw
new
ResolvedQueueError
();
}
promise_stack
.
push
(
promise_stack
[
promise_stack
.
length
-
1
].
then
(
done
,
fail
)
);
function_stack
.
push
(
done
,
fail
);
return
this
;
};
Promise
.
call
(
this
,
function
(
done
,
fail
)
{
resolveQueue
=
done
;
rejectQueue
=
fail
;
// Resolve by default
function_stack
.
push
(
resolve
,
undefined
);
handleDone
();
},
function
()
{
// Skip not executed .push
function_stack
=
[];
// Cancel currently running promise
if
((
current_promise
!==
undefined
)
&&
(
typeof
current_promise
.
cancel
===
"
function
"
))
{
current_promise
.
cancel
();
}
});
return
this
;
};
...
...
Romain Courteaud
@romain
mentioned in commit
9b922f24
·
Feb 25, 2020
mentioned in commit
9b922f24
mentioned in commit 9b922f241651d957fb358158faceb8f9e8473d96
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