Calling asynchronous functions in renderer now doesn't block browser.
This commit is contained in:
parent
085f0a2544
commit
14de58a6b7
2 changed files with 17 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
binding = process.atomBinding 'dialog'
|
binding = process.atomBinding 'dialog'
|
||||||
|
v8Util = process.atomBinding 'v8_util'
|
||||||
BrowserWindow = require 'browser-window'
|
BrowserWindow = require 'browser-window'
|
||||||
|
|
||||||
fileDialogProperties =
|
fileDialogProperties =
|
||||||
|
@ -72,3 +73,6 @@ module.exports =
|
||||||
String(options.detail),
|
String(options.detail),
|
||||||
window,
|
window,
|
||||||
callback
|
callback
|
||||||
|
|
||||||
|
# Mark standard asynchronous functions.
|
||||||
|
v8Util.setHiddenValue f, 'asynchronous', true for k, f of module.exports
|
||||||
|
|
|
@ -61,6 +61,17 @@ unwrapArgs = (processId, routingId, args) ->
|
||||||
|
|
||||||
args.map metaToValue
|
args.map metaToValue
|
||||||
|
|
||||||
|
# Call a function and send reply asynchronously if it's a an asynchronous
|
||||||
|
# style function and the caller didn't pass a callback.
|
||||||
|
callFunction = (event, processId, routingId, func, caller, args) ->
|
||||||
|
if v8Util.getHiddenValue(func, 'asynchronous') and typeof args[args.length - 1] isnt 'function'
|
||||||
|
args.push (ret) ->
|
||||||
|
event.returnValue = valueToMeta processId, routingId, ret
|
||||||
|
func.apply caller, args
|
||||||
|
else
|
||||||
|
ret = func.apply caller, args
|
||||||
|
event.returnValue = valueToMeta processId, routingId, ret
|
||||||
|
|
||||||
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
||||||
try
|
try
|
||||||
event.returnValue = valueToMeta processId, routingId, require(module)
|
event.returnValue = valueToMeta processId, routingId, require(module)
|
||||||
|
@ -100,8 +111,7 @@ ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) ->
|
||||||
try
|
try
|
||||||
args = unwrapArgs processId, routingId, args
|
args = unwrapArgs processId, routingId, args
|
||||||
func = objectsRegistry.get id
|
func = objectsRegistry.get id
|
||||||
ret = func.apply global, args
|
callFunction event, processId, routingId, func, global, args
|
||||||
event.returnValue = valueToMeta processId, routingId, ret
|
|
||||||
catch e
|
catch e
|
||||||
event.returnValue = errorToMeta e
|
event.returnValue = errorToMeta e
|
||||||
|
|
||||||
|
@ -119,8 +129,7 @@ ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, arg
|
||||||
try
|
try
|
||||||
args = unwrapArgs processId, routingId, args
|
args = unwrapArgs processId, routingId, args
|
||||||
obj = objectsRegistry.get id
|
obj = objectsRegistry.get id
|
||||||
ret = obj[method].apply(obj, args)
|
callFunction event, processId, routingId, obj[method], obj, args
|
||||||
event.returnValue = valueToMeta processId, routingId, ret
|
|
||||||
catch e
|
catch e
|
||||||
event.returnValue = errorToMeta e
|
event.returnValue = errorToMeta e
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue