wrapWithUvloop waker (#380)
This commit is contained in:
parent
8dce10bda8
commit
e6c2eb4380
@ -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');
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user