-
Notifications
You must be signed in to change notification settings - Fork 127
Promise vs Callback
Marc Pascual edited this page Jun 16, 2020
·
3 revisions
All methods in this plugin return promises, both for Capacitor and Cordova versions, which are resolved when the plugin has done the asked action. However, Cordova also allows passing callback functions as parameters, which will be called after the plugin has done that same asked action.
The following code will have the same behaviour:
try {
const data = await admob.createBannerView(options);
console.log('Banner created succesfully returning:', data);
} catch (err) {
console.log('Error creating banner:', err);
}
const onSuccess = (data) => {
console.log('Banner created succesfully returning:', data);
}
const onFailure = (err) => {
console.log('Error creating banner:', err);
}
admob.createBannerView(options, onSuccess, onFailure);