Skip to content

Instantly share code, notes, and snippets.

@sallar
Created February 22, 2018 17:10
Show Gist options
  • Save sallar/b1e2163934a3e933ea6458f33f20e2fe to your computer and use it in GitHub Desktop.
Save sallar/b1e2163934a3e933ea6458f33f20e2fe to your computer and use it in GitHub Desktop.
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