Skip to content

Commit 2f339fd

Browse files
committed
Fix comms processing order
1 parent bc4e4c8 commit 2f339fd

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/widget.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ export class CanvasManagerModel extends WidgetModel {
137137
initialize(attributes: any, options: any) {
138138
super.initialize(attributes, options);
139139

140-
this.on('msg:custom', this.onCommand.bind(this));
140+
this.on('msg:custom', (command: any, buffers: any) => {
141+
this.currentProcessing = this.currentProcessing.then(async () => {
142+
await this.onCommand(command, buffers);
143+
});
144+
});
141145
}
142146

143147
private async onCommand(command: any, buffers: any) {
@@ -359,6 +363,7 @@ export class CanvasManagerModel extends WidgetModel {
359363
}
360364

361365
private currentCanvas: CanvasModel;
366+
private currentProcessing: Promise<void> = Promise.resolve();
362367
private canvasesToUpdate: CanvasModel[] = [];
363368

364369
static model_name = 'CanvasManagerModel';

ui-tests/tests/notebooks/ipycanvas.ipynb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,13 @@
908908
"canvas = Canvas(width=300, height=300)\n",
909909
"canvas2 = Canvas(width=600, height=300)\n",
910910
"\n",
911-
"with hold_canvas():\n",
912-
" canvas.fill_style = '#a9cafc'\n",
913-
" canvas.fill_rect(0, 0, 300, 300)\n",
911+
"canvas.fill_style = '#a9cafc'\n",
912+
"canvas.fill_rect(0, 0, 300, 300)\n",
914913
"\n",
915-
" canvas.draw_image(sprite1, 50, 50)\n",
916-
" canvas.draw_image(sprite2, 100, 100)\n",
917-
" canvas2.draw_image(canvas, 0, 0)\n",
918-
" canvas2.draw_image(canvas, 300, 0)\n",
914+
"canvas.draw_image(sprite1, 50, 50)\n",
915+
"canvas.draw_image(sprite2, 100, 100)\n",
916+
"canvas2.draw_image(canvas, 0, 0)\n",
917+
"canvas2.draw_image(canvas, 300, 0)\n",
919918
"\n",
920919
"canvas2"
921920
]

0 commit comments

Comments
 (0)