BlazorExtensions / Canvas

HTML5 Canvas API implementation for Microsoft Blazor
MIT License
614 stars 146 forks source link

Synchronous drawing API #59

Open ustims opened 4 years ago

ustims commented 4 years ago

Hi. I'm trying to build a drawing library which will target both Blazor and Xamarin SkiaSharp. The problem I faced is that SkiaSharp apis are synchronous while blazor apis are async..

So I'm trying to make Blazor Canvas methods to work synchronously.

As far as I see Blazor synchronous methods are deprecated but are based on .GetAwaiter().GetResult() internally (in CallMethod<T>). I tried using that in test project:

//await this._context.FillRectAsync(10, 100, 100, 100);
this._context.FillRectAsync(10, 100, 100, 100).GetAwaiter().GetResult();

which didn't work and caused browser to hang.

My question is: are there any plans on restoring synchronous apis in future? Maybe there is an easy way to call canvas apis synchronously? Maybe I'm looking at wrong direction and it's better to have my library's drawing methods asynchronous but find a way to execute async code from SkiaSharp OnCanvasViewPaintSurface?

I'm yet to dig deeper into how SynchronizationContext works in blazor but wanted to check with somebody more experienced first.

Thanks!