node-addon-api icon indicating copy to clipboard operation
node-addon-api copied to clipboard

src: fix implementation of AsyncProgressWorker::Signal

Open KevinEady opened this issue 2 years ago • 2 comments

Fix implementation of AsyncProgressWorker::Signal and AsyncProgressQueueWorker::Signal

Fixes: #1095 Fixes: #1081

KevinEady avatar Oct 07 '22 14:10 KevinEady

@KevinEady could you add a short explanation of how using SendProgress instead of Signal resolves the problem? I think I know but not 100% sure.

@legendecas would be good if you reviewed as well since it seems like you were in the loop on the discussions of the original problem.

mhdawson avatar Oct 14 '22 17:10 mhdawson

Hi @mhdawson ,

The AsyncProgress[Queue]Worker::Signal() method is supposed to call the OnProgress worker with nullptr for data and 0 for count. The main change is not using NonBlockingCall() but instead using SendProgress_().

I went about this PR by looking at the existing test we have:

https://github.com/nodejs/node-addon-api/blob/a8afb2d73c368a23ab9ed157b67e1cf8587d39c4/test/async_progress_worker.cc#L82-L83

Since sending nullptr with 0 data is allowed, I wrote Signal() to behave in this manner, by basically making progress.Signal() behave as progress.Send(nullptr, 0), which means using the SendProgress_() method.

Hope this clarifies!

Thanks, Kevin

KevinEady avatar Oct 15 '22 12:10 KevinEady

@KevinEady many thanks for the explanation

mhdawson avatar Oct 20 '22 21:10 mhdawson

Another thing @legendecas , i did not make any changes to AsyncProgressQueueWorker regarding a state member like 1f2cd71. Since the queue variety of the progress worker stores all progress updates, I don't think it is necessary to update the queue worker. Does this sound right?

KevinEady avatar Nov 14 '22 14:11 KevinEady

Landed as edf630cc79eeef1029d3c1e7e47dcbcf2ab6d47b

mhdawson avatar Dec 02 '22 18:12 mhdawson