Prefer event.returnValue to event.result for sync messages.
This commit is contained in:
parent
50b5272354
commit
b225a59a15
3 changed files with 6 additions and 4 deletions
|
@ -18,7 +18,7 @@ Emitted when renderer sent a message to the browser.
|
||||||
* `routingId` Integer
|
* `routingId` Integer
|
||||||
|
|
||||||
Emitted when renderer sent a synchronous message to the browser. The receiver
|
Emitted when renderer sent a synchronous message to the browser. The receiver
|
||||||
should store the result in `event.result`.
|
should store the result in `event.returnValue`.
|
||||||
|
|
||||||
**Note:** Due to the limitation of `EventEmitter`, returning value in the
|
**Note:** Due to the limitation of `EventEmitter`, returning value in the
|
||||||
event handler has no effect, so we have to store the result by using the
|
event handler has no effect, so we have to store the result by using the
|
||||||
|
|
|
@ -30,7 +30,7 @@ An example of sending synchronous message from renderer to browser:
|
||||||
// In browser:
|
// In browser:
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc');
|
||||||
ipc.on('browser-data-request', function(event, processId, routingId, message) {
|
ipc.on('browser-data-request', function(event, processId, routingId, message) {
|
||||||
event.result = 'THIS SOME DATA FROM THE BROWSER';
|
event.returnValue = 'THIS SOME DATA FROM THE BROWSER';
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@ class Ipc extends EventEmitter
|
||||||
ipc.send('ATOM_INTERNAL_MESSAGE', args...)
|
ipc.send('ATOM_INTERNAL_MESSAGE', args...)
|
||||||
|
|
||||||
sendSync: (args...) ->
|
sendSync: (args...) ->
|
||||||
ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', 'sync-message', args...).result
|
msg = ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', 'sync-message', args...)
|
||||||
|
msg.returnValue ? msg.result
|
||||||
|
|
||||||
sendChannelSync: (args...) ->
|
sendChannelSync: (args...) ->
|
||||||
ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', args...).result
|
msg = ipc.sendSync('ATOM_INTERNAL_MESSAGE_SYNC', args...)
|
||||||
|
msg.returnValue ? msg.result
|
||||||
|
|
||||||
module.exports = new Ipc
|
module.exports = new Ipc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue