help icon indicating copy to clipboard operation
help copied to clipboard

uv_async_send problem in windows not in mac or linux

Open deshan opened this issue 5 years ago • 1 comments

Hi,

I have created an electron app and below code works as expected on mac and linux. But in windows it works only once (first time app start). From the second run of the electron app uv_async_send not execute the callback until restart the pc. `

class Reader {

uv_async_t* asyncHandle = nullptr;

// Start
void start() {
	uv_loop_t* loop = uv_default_loop();
	asyncHandle = new uv_async_t;
	asyncHandle->data = this;
	
	uv_async_init(loop, asyncHandle, [] (uv_async_t* handle) {
		if(handle->data) {
			printf("Callback is called");
		}
	}
}

// Stop
void stop(){
	uv_close(reinterpret_cast<uv_handle_t*>(asyncHandle), [] (uv_handle_s* handle) {
		delete static_cast<uv_handle_t*>(handle);
	});
	asyncHandle = nullptr;
}

// calling from different thread
static void downloadProgress(Reader* pointer, int progress){
	// Do something
	printf("Has Progress");
	uv_async_send(pointer->asyncHandle);
}}

`

I am properly call the start and stop functions.

Output First time

Has Progress Callback is called Has Progress Callback is called

Run on second time, call back not called

Has Progress Has Progress Has Progress Has Progress

deshan avatar Jul 22 '20 20:07 deshan

Still struggling with this issue. Some more findings, In windows environment, this has no issues when tries with

  1. When use with node (eg : node app.js)
  2. As an electron app(without react)

The problem arises only when integrated with react and webpack

deshan avatar Aug 05 '20 16:08 deshan