wrapWithUvloop waker (#380)

This commit is contained in:
Atul R 2020-01-28 20:21:06 +01:00 committed by GitHub
parent 8dce10bda8
commit e6c2eb4380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import { EventEmitter } from 'events';
import { NativeElement, Component, NativeRawPointer } from './Component';
import { wrapWithActivateUvLoop } from '../utils/helpers';
function addDefaultErrorHandler(native: NativeElement, emitter: EventEmitter): void {
native.subscribeToQtEvent('error');
@ -38,7 +39,8 @@ export abstract class EventWidget<Signals extends {}> extends Component {
super();
if (native.initNodeEventEmitter) {
this.emitter = new EventEmitter();
native.initNodeEventEmitter(this.emitter.emit.bind(this.emitter));
this.emitter.emit = wrapWithActivateUvLoop(this.emitter.emit.bind(this.emitter));
native.initNodeEventEmitter(this.emitter.emit);
} else {
throw new Error('initNodeEventEmitter not implemented on native side');
}

View File

@ -9,17 +9,7 @@
This is required inorder to make the timers work nicely due to merger of event loops
*/
function noop(): void {
return;
}
const wrapWithActivateUvLoop = (func: Function) => {
return (...args: any[]): any => {
const activateUvLoop = (process as any).activateUvLoop || noop;
activateUvLoop();
return func(...args);
};
};
import { wrapWithActivateUvLoop } from '../utils/helpers';
function main(): void {
process.nextTick = wrapWithActivateUvLoop(process.nextTick);

View File

@ -9,3 +9,15 @@ export function checkIfNativeElement(arg: any): boolean {
export function checkIfNapiExternal(arg: any): boolean {
return addon.NUtils.isNapiExternal(arg);
}
function noop(): void {
return;
}
export const wrapWithActivateUvLoop = (func: Function) => {
return (...args: any[]): any => {
const activateUvLoop = (process as any).activateUvLoop || noop;
activateUvLoop();
return func(...args);
};
};