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
29822afe
Commit
29822afe
authored
Feb 25, 2020
by
Romain Courteaud
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queue: cancelling stop the .push result propagation
parent
a6b294f3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
181 additions
and
15 deletions
+181
-15
lib/rsvp/queue.js
lib/rsvp/queue.js
+2
-2
test/tests/extension_test.js
test/tests/extension_test.js
+179
-13
No files found.
lib/rsvp/queue.js
View file @
29822afe
...
...
@@ -25,8 +25,8 @@ var Queue = function() {
}
function
canceller
()
{
for
(
var
i
=
0
;
i
<
2
;
i
++
)
{
promise_list
[
i
].
cancel
();
for
(
var
i
=
promise_list
.
length
;
i
>
0
;
i
--
)
{
promise_list
[
i
-
1
].
cancel
();
}
}
...
...
test/tests/extension_test.js
View file @
29822afe
...
...
@@ -2211,8 +2211,10 @@ describe("`RSVP.Queue`", function () {
});
it
(
'
should throw if the queue is rejected
'
,
function
(
done
)
{
var
queue
=
new
RSVP
.
Queue
();
queue
.
cancel
();
var
queue
=
new
RSVP
.
Queue
()
.
push
(
undefined
,
function
()
{
return
RSVP
.
reject
(
1
);
});
setTimeout
(
function
()
{
assert
.
throws
(
function
()
{
...
...
@@ -2221,6 +2223,15 @@ describe("`RSVP.Queue`", function () {
done
();
},
20
);
});
it
(
'
should throw if the queue is cancelled
'
,
function
()
{
var
queue
=
new
RSVP
.
Queue
();
queue
.
cancel
();
assert
.
throws
(
function
()
{
queue
.
push
();
},
RSVP
.
ResolvedQueueError
);
});
});
describe
(
"
`Queue` instance
"
,
function
()
{
...
...
@@ -2251,7 +2262,7 @@ describe("`RSVP.Queue`", function () {
it
(
'
get the fulfillmentValue of the last queue entry
'
,
function
(
done
)
{
var
queue
=
new
RSVP
.
Queue
();
queue
.
push
(
function
()
{
return
"
foo
"
return
"
foo
"
;
});
setTimeout
(
function
()
{
...
...
@@ -2326,25 +2337,180 @@ describe("`RSVP.Queue`", function () {
done
();
},
20
);
});
});
it
(
'
cancel also cancels the remaining promise
'
,
function
(
done
)
{
describe
(
"
`cancel`
"
,
function
()
{
it
(
'
should be a function
'
,
function
()
{
var
queue
=
new
RSVP
.
Queue
();
assert
.
equal
(
typeof
queue
.
cancel
,
"
function
"
);
});
it
(
'
should reject with a CancellationError
'
,
function
(
done
)
{
var
queue
=
new
RSVP
.
Queue
(),
pushed_result
;
queue
.
push
(
function
(
)
{
return
RSVP
.
timeout
(
1
)
;
error
;
queue
.
then
(
null
,
function
(
e
)
{
error
=
e
;
});
queue
.
push
(
undefined
,
function
(
value
)
{
pushed_result
=
value
;
throw
value
;
queue
.
cancel
();
setTimeout
(
function
()
{
assert
(
error
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
queue
.
isRejected
,
true
);
assert
(
queue
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
done
();
},
20
);
});
it
(
'
does nothing on a `fulfilled` queue
'
,
function
(
done
)
{
var
queue
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
'
ok
'
;
}),
result
=
'
MARKER1
'
,
error
=
'
MARKER2
'
;
queue
.
then
(
function
(
e
)
{
result
=
e
;
});
queue
.
fail
(
function
(
e
)
{
error
=
e
;
});
setTimeout
(
function
()
{
queue
.
cancel
();
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
undefined
);
assert
.
equal
(
queue
.
isFulfilled
,
true
);
assert
.
equal
(
queue
.
fulfillmentValue
,
'
ok
'
);
assert
.
equal
(
result
,
'
ok
'
);
assert
.
equal
(
error
,
'
MARKER2
'
);
done
();
},
20
);
},
20
);
});
it
(
'
does nothing on a `rejected` queue
'
,
function
(
done
)
{
var
queue
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
throw
'
ko
'
;
}),
result
=
'
MARKER1
'
,
error
=
'
MARKER2
'
;
queue
.
then
(
function
(
e
)
{
result
=
e
;
});
queue
.
fail
(
function
(
e
)
{
error
=
e
;
});
setTimeout
(
function
()
{
queue
.
cancel
();
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
true
);
assert
.
equal
(
queue
.
isFulfilled
,
undefined
);
assert
.
equal
(
queue
.
rejectedReason
,
'
ko
'
);
assert
.
equal
(
result
,
'
MARKER1
'
);
assert
.
equal
(
error
,
'
ko
'
);
done
();
},
20
);
},
20
);
});
it
(
'
should `cancel` pending success `thenable`
'
,
function
(
done
)
{
var
thenable_cancel_called
=
false
,
thenable_ongoing
=
false
,
later_success_thenable_called
=
false
,
later_error_thenable_called
=
false
,
queue
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
new
RSVP
.
Promise
(
function
()
{
thenable_ongoing
=
true
;
},
function
()
{
thenable_cancel_called
=
true
;
});
})
.
push
(
// Should be skipped
function
()
{
later_success_thenable_called
=
true
;},
function
()
{
later_error_thenable_called
=
true
;}
),
result
=
'
MARKER1
'
,
error
=
'
MARKER2
'
;
queue
.
then
(
function
(
e
)
{
result
=
e
;
});
queue
.
fail
(
function
(
e
)
{
error
=
e
;
});
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
undefined
);
assert
.
equal
(
queue
.
isFulfilled
,
undefined
);
assert
.
equal
(
thenable_ongoing
,
true
);
queue
.
cancel
();
assert
.
equal
(
thenable_cancel_called
,
true
);
setTimeout
(
function
()
{
assert
(
pushed_result
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
queue
.
isRejected
,
true
);
assert
.
equal
(
queue
.
isFulfilled
,
undefined
);
assert
(
queue
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
result
,
'
MARKER1
'
);
assert
(
error
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
later_success_thenable_called
,
false
);
assert
.
equal
(
later_error_thenable_called
,
false
);
done
();
},
20
);
},
20
);
});
it
(
'
should `cancel` pending error `thenable`
'
,
function
(
done
)
{
var
thenable_cancel_called
=
false
,
thenable_ongoing
=
false
,
later_success_thenable_called
=
false
,
later_error_thenable_called
=
false
,
queue
=
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
reject
(
1
);
})
.
push
(
undefined
,
function
()
{
return
new
RSVP
.
Promise
(
function
()
{
thenable_ongoing
=
true
;
},
function
()
{
thenable_cancel_called
=
true
;
});
})
.
push
(
// Should be skipped
function
()
{
later_success_thenable_called
=
true
;},
function
()
{
later_error_thenable_called
=
true
;}
),
result
=
'
MARKER1
'
,
error
=
'
MARKER2
'
;
queue
.
then
(
function
(
e
)
{
result
=
e
;
});
queue
.
fail
(
function
(
e
)
{
error
=
e
;
});
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
undefined
);
assert
.
equal
(
queue
.
isFulfilled
,
undefined
);
assert
.
equal
(
thenable_ongoing
,
true
);
queue
.
cancel
();
assert
.
equal
(
thenable_cancel_called
,
true
);
setTimeout
(
function
()
{
assert
.
equal
(
queue
.
isRejected
,
true
);
assert
.
equal
(
queue
.
isFulfilled
,
undefined
);
assert
(
queue
.
rejectedReason
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
result
,
'
MARKER1
'
);
assert
(
error
instanceof
RSVP
.
CancellationError
);
assert
.
equal
(
later_success_thenable_called
,
false
);
assert
.
equal
(
later_error_thenable_called
,
false
);
done
();
},
20
);
},
20
);
});
});
});
Romain Courteaud
@romain
mentioned in merge request
erp5!1446
·
Sep 02, 2021
mentioned in merge request
erp5!1446
mentioned in merge request erp5!1446
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