Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
45f127cc
Commit
45f127cc
authored
Feb 21, 2020
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bad usage of queue.
Ensure to cancel the ongoing promise if queue is cancelled.
parent
b413244c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
197 additions
and
0 deletions
+197
-0
renderjs.js
renderjs.js
+17
-0
test/mutex_test.js
test/mutex_test.js
+33
-0
test/renderjs_test.js
test/renderjs_test.js
+147
-0
No files found.
renderjs.js
View file @
45f127cc
...
...
@@ -56,6 +56,11 @@
return
new
RSVP
.
Queue
()
.
push
(
function
returnPushableResult
()
{
return
result
;
},
function
(
e
)
{
if
((
result
!==
undefined
)
&&
(
result
.
cancel
!==
undefined
))
{
result
.
cancel
();
}
throw
e
;
});
}
...
...
@@ -426,6 +431,12 @@
var
queue
=
new
RSVP
.
Queue
()
.
push
(
function
waitForPromiseToMonitor
()
{
return
promise_to_monitor
;
},
function
(
e
)
{
if
((
promise_to_monitor
!==
undefined
)
&&
(
promise_to_monitor
.
cancel
!==
undefined
))
{
promise_to_monitor
.
cancel
();
}
throw
e
;
})
.
push
(
function
handlePromiseToMonitorSuccess
(
fulfillmentValue
)
{
// Promise to monitor is fullfilled, remove it from the list
...
...
@@ -608,6 +619,7 @@
gadget
.
__job_dict
[
name
].
cancel
();
}
gadget
.
__job_dict
[
name
]
=
job_promise
;
// gadget.__monitor.monitor(job_promise
gadget
.
__monitor
.
monitor
(
new
RSVP
.
Queue
()
.
push
(
function
waitForJobPromise
()
{
return
job_promise
;
...
...
@@ -1203,6 +1215,11 @@
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
result
;
},
function
(
e
)
{
if
((
result
!==
undefined
)
&&
(
result
.
cancel
!==
undefined
))
{
result
.
cancel
();
}
throw
e
;
})
.
push
(
function
setAsyncGadgetInstanceHTMLContext
(
gadget_instance
)
{
return
setGadgetInstanceHTMLContext
(
gadget_instance
,
options
,
...
...
test/mutex_test.js
View file @
45f127cc
...
...
@@ -253,6 +253,39 @@
});
});
test
(
'
lockAndRun cancel stop first execution
'
,
function
()
{
var
mutex
=
new
Mutex
(),
counter
=
0
;
stop
();
expect
(
2
);
function
assertCounter
(
value
)
{
equal
(
counter
,
value
);
counter
+=
1
;
}
function
callback1
()
{
assertCounter
(
0
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
delay
(
50
);
})
.
push
(
function
()
{
assertCounter
(
-
999
);
ok
(
false
,
'
Should not reach that code
'
);
});
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
promise
=
mutex
.
lockAndRun
(
callback1
);
promise
.
cancel
(
'
cancel callback1
'
);
return
RSVP
.
delay
(
200
);
})
.
push
(
function
()
{
assertCounter
(
1
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
lockAndRun cancel does not cancel previous execution
'
,
function
()
{
var
mutex
=
new
Mutex
(),
...
...
test/renderjs_test.js
View file @
45f127cc
...
...
@@ -2229,6 +2229,153 @@
});
});
test
(
'
mutex prevent concurrent execution
'
,
function
()
{
// Subclass RenderJSGadget to not pollute its namespace
var
Klass
=
function
()
{
RenderJSGadget
.
call
(
this
);
},
gadget
,
counter
=
0
;
Klass
.
prototype
=
new
RenderJSGadget
();
Klass
.
prototype
.
constructor
=
Klass
;
Klass
.
declareMethod
=
RenderJSGadget
.
declareMethod
;
gadget
=
new
Klass
();
function
assertCounter
(
value
)
{
equal
(
counter
,
value
);
counter
+=
1
;
}
Klass
.
declareMethod
(
'
testFoo
'
,
function
(
expected_counter
)
{
assertCounter
(
expected_counter
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
delay
(
50
);
})
.
push
(
function
()
{
assertCounter
(
expected_counter
+
1
);
return
counter
;
});
},
{
mutex
:
'
foo
'
});
// method can be called
stop
();
expect
(
10
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
([
gadget
.
testFoo
(
0
),
gadget
.
testFoo
(
2
),
gadget
.
testFoo
(
4
)
]);
})
.
push
(
function
(
result_list
)
{
equal
(
result_list
[
0
],
2
);
equal
(
result_list
[
1
],
4
);
equal
(
result_list
[
2
],
6
);
assertCounter
(
6
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
mutex first cancellation stop execution
'
,
function
()
{
// Subclass RenderJSGadget to not pollute its namespace
var
Klass
=
function
()
{
RenderJSGadget
.
call
(
this
);
},
gadget
,
counter
=
0
;
Klass
.
prototype
=
new
RenderJSGadget
();
Klass
.
prototype
.
constructor
=
Klass
;
Klass
.
declareMethod
=
RenderJSGadget
.
declareMethod
;
gadget
=
new
Klass
();
function
assertCounter
(
value
)
{
equal
(
counter
,
value
);
counter
+=
1
;
}
Klass
.
declareMethod
(
'
testFoo
'
,
function
(
expected_counter
)
{
assertCounter
(
expected_counter
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
delay
(
50
);
})
.
push
(
function
()
{
assertCounter
(
expected_counter
+
1
);
ok
(
false
,
'
Should not reach that code
'
);
});
},
{
mutex
:
'
foo
'
});
// method can be called
stop
();
expect
(
2
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
// Immediately cancel the first call
gadget
.
testFoo
(
0
).
cancel
();
return
RSVP
.
delay
(
200
);
})
.
push
(
function
()
{
assertCounter
(
1
);
})
.
always
(
function
()
{
start
();
});
});
test
(
'
not mutex first cancellation stop execution
'
,
function
()
{
// Subclass RenderJSGadget to not pollute its namespace
var
Klass
=
function
()
{
RenderJSGadget
.
call
(
this
);
},
gadget
,
counter
=
0
;
Klass
.
prototype
=
new
RenderJSGadget
();
Klass
.
prototype
.
constructor
=
Klass
;
Klass
.
declareMethod
=
RenderJSGadget
.
declareMethod
;
gadget
=
new
Klass
();
function
assertCounter
(
value
)
{
equal
(
counter
,
value
);
counter
+=
1
;
}
Klass
.
declareMethod
(
'
testFoo
'
,
function
(
expected_counter
)
{
// console.log('aaaaa', expected_counter);
assertCounter
(
expected_counter
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
delay
(
50
);
})
.
push
(
function
()
{
// console.log('bbbbbbb', expected_counter);
assertCounter
(
expected_counter
+
1
);
ok
(
false
,
'
Should not reach that code
'
);
});
});
// method can be called
stop
();
expect
(
2
);
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
// Immediately cancel the first call
gadget
.
testFoo
(
0
).
cancel
();
return
RSVP
.
delay
(
200
);
})
.
push
(
function
()
{
assertCounter
(
1
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// RenderJSGadgetKlass.ready
/////////////////////////////////////////////////////////////////
...
...
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