StackBlur
StackBlur copied to clipboard
Is there an easy way to make the canvasRGBA method cancellable?
Sorry, what do you mean by cancelable? It's not an event, so not clear what you mean.
The method will silently exit early if the last (6th) argument is not a number (or a string that resolves to a number) or if it is less than 1--in case that's what you meant.
Or did you mean that you wanted a method that also fed getImageDataFromCanvas
to processImageDataRGBA
, but returned the resulting imageData
instead of passing it to putImageData
?
Thanks for the reply!
I guess what I mean is can I cancel the execution of the function mid way through? Set a flag on one of the loops and abort the function early if a flag is set to true? The scenario is we render a heat map and there are controls to move back and forward in time, which triggers the render function. So if a user clicks quickly the render functions get queued up and lock up the UI.
So the behaviour would be similar to resolving a deferred promise to cancel an Ajax network request.
My understanding is I could wrap it in a promise or observable, but I still can’t cancel the function so it would still get processed asynchronously.
Hope that makes sense.
Regards, Rod On 5 Jul 2020, 5:26 PM +1000, Brett Zamir [email protected], wrote:
Sorry, what do you mean by cancelable? It's not an event, so not clear what you mean. The method will silently exit early if the last (6th) argument is not a number (or a string that resolves to a number) or if it is less than 1--in case that's what you meant. Or did you mean that you wanted a method that also fed getImageDataFromCanvas to processImageDataRGBA, but returned the resulting imageData instead of passing it to putImageData? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Yes, the function is not implemented asynchronously, so there'd be no way to get alerted even if there were a flag that was checked (a callback could be added within the loops and passed some data, but it would run synchronously, and I wouldn't think that would be of any use).
The most granular option would be to make a separate asynchronous version of processImageDataRGBA
, e.g., turning the method into a generator which instead of looping to build an ImageData
object, yielded an individual pixel index and value which could in turn be set by the caller on their own ImageData
object (and updated on the canvas as desired), and then, with the generator iterated further at whatever interval the caller wanted (avoiding lock-up)--and optionally canceled during such iteration.
Alternatively, perhaps #16 might help enough to avoid your issue in the first place.