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
9b922f24
Commit
9b922f24
authored
Feb 25, 2020
by
Romain Courteaud
🐸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Experiment other implementations."
This reverts commit
8dcbf352
.
parent
8dcbf352
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
73 deletions
+46
-73
lib/rsvp/queue.js
lib/rsvp/queue.js
+46
-73
No files found.
lib/rsvp/queue.js
View file @
9b922f24
...
@@ -17,93 +17,66 @@ var Queue = function() {
...
@@ -17,93 +17,66 @@ var Queue = function() {
return
new
Queue
();
return
new
Queue
();
}
}
var
function_stack
=
[],
var
promise_stack
=
[],
resolveQueue
,
// handleQueue
rejectQueue
,
detect_end_index
=
1
;
queue
=
this
,
current_promise
=
null
,
handleDone
,
handleReject
,
next_function
;
handleDone
=
function
(
result
)
{
Promise
.
call
(
this
,
function
(
resolveQueue
,
rejectQueue
)
{
if
(
queue
.
isRejected
)
{
var
detectQueueSuccess
,
return
;
detectQueueError
;
}
if
(
function_stack
.
length
>
0
)
{
function
handleQueue
()
{
next_function
=
function_stack
.
shift
();
if
(
promise_stack
.
length
===
detect_end_index
)
{
// Remove fail handler
return
true
;
function_stack
.
shift
();
if
(
next_function
===
undefined
)
{
return
handleDone
(
result
);
}
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
;
promise_stack
.
splice
(
0
,
detect_end_index
);
}
resolveQueue
(
result
);
};
handleReject
=
function
(
error
)
{
promise_stack
.
push
(
if
(
queue
.
isRejected
)
{
promise_stack
[
promise_stack
.
length
-
1
].
then
(
detectQueueSuccess
,
return
;
detectQueueError
)
);
detect_end_index
=
promise_stack
.
length
;
return
false
;
}
}
if
(
function_stack
.
length
>
0
)
{
// Remove done handler
detectQueueSuccess
=
function
(
fulfillmentValue
)
{
function_stack
.
shift
();
if
(
handleQueue
())
{
next_function
=
function_stack
.
shift
();
return
resolveQueue
(
fulfillmentValue
);
if
(
next_function
===
undefined
)
{
return
handleReject
(
error
);
}
try
{
current_promise
=
next_function
.
call
(
null
,
error
);
}
catch
(
e
)
{
return
handleReject
(
e
);
}
}
if
((
current_promise
!==
undefined
)
&&
return
fulfillmentValue
;
(
typeof
current_promise
.
then
===
"
function
"
))
{
};
current_promise
.
then
(
handleDone
,
handleReject
);
}
else
{
detectQueueError
=
function
(
rejectedReason
)
{
handleDone
(
current_promise
);
if
(
handleQueue
())
{
return
rejectQueue
(
rejectedReason
);
}
}
return
;
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
();
}
}
rejectQueue
(
error
);
};
}
)
;
this
.
push
=
function
(
done
,
fail
)
{
this
.
push
=
function
(
done
,
fail
)
{
if
(
this
.
isFulfilled
||
this
.
isRejected
||
this
.
isCancelled
)
{
if
(
this
.
isFulfilled
||
this
.
isRejected
)
{
throw
new
ResolvedQueueError
();
throw
new
ResolvedQueueError
();
}
}
function_stack
.
push
(
done
,
fail
);
promise_stack
.
push
(
promise_stack
[
promise_stack
.
length
-
1
].
then
(
done
,
fail
)
);
return
this
;
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
;
return
this
;
};
};
...
...
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