Skip to content

Instantly share code, notes, and snippets.

@sallar sallar/main.js
Created Feb 22, 2018

Embed
What would you like to do?
Electron IPC Enqueue
ipc.on('channel:enqueue', (e, payload) => {
const { channelName, stack, id } = payload;
getQueue()
.channel(channelName)
.enqueue(
() => {
return new Promise(resolve => {
ipc.once(`channel:resolve:${id}`, resolve);
e.sender.webContents.send(`channel:execute:${id}`);
});
},
undefined,
stack
);
});
export function enqueueInMain(channelName, fn, stack) {
const id = uuid.v4();
ipc.once(`channel:execute:${id}`, async () => {
const output = fn();
if (output instanceof Promise) {
await output;
}
ipc.send(`channel:resolve:${id}`);
});
ipc.send('channel:enqueue', {
channelName,
stack,
id
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.