I have seen some confusion when it comes to using invokeCFClientFunction. I have been asked this question a few times, more recently on LinkedIn, so I thought explaining it in a blog post might be a good idea.
cfclient also makes calling asynchronous functions of PhoneGap easy by providing synchronous access to them. All device APIs are asynchronous in nature, but in cfclient block you call then as synchronous functions and ColdFusion translates them to asynchronous PhoneGap functions. All function starting with ‘cfclient.’, e.g. cfclient.camera.getPicture(), are asynchronous. In addition to device APIs, data access function, executeQuery and tag, cfquery, are also asynchronous in cfclient.
If you execute this code in Chrome/Safari, you will see following output –
If you execute the code now, you will see following output –
After creating database. ret = true
Note that ColdFusion decides if a UDF in cfclient is asynchronous after analyzing all the function calls from that UDF recursively – so if UDF func1 in cfclient calls another UDF func2 and if func2 calls a device/database API then func1 is also marked as asynchronous even if it does not directly call any device/database function.