Skip to content

Commit 558ec34

Browse files
committed
background CPU rendering, check if channel is closed before rendering
1 parent f9f4c00 commit 558ec34

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/web/page/templates.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ impl TemplateData {
5353
self.rendering_threadpool.spawn({
5454
let templates = self.clone();
5555
move || {
56-
// `.send` only fails when the receiver is dropped,
57-
// at which point we don't need the result any more.
58-
let _ = send.send(render_fn(&templates));
56+
// the job may have been queued on the thread-pool for a while,
57+
// if the request was closed in the meantime the receiver should have
58+
// dropped and we don't need to bother rendering the template
59+
if !send.is_closed() {
60+
// `.send` only fails when the receiver is dropped while we were rendering,
61+
// at which point we don't need the result any more.
62+
let _ = send.send(render_fn(&templates));
63+
}
5964
}
6065
});
6166

0 commit comments

Comments
 (0)