-
new Promise()
-
The Promise constructor is for internal use only. Promise objects returned by other API methods are created with this constructor.
Methods
-
then(onFulfilled, onRejected)
-
Use
.then(...)to register callbacks to access the current or eventual value, or reason, of the promise.A promise is in one of three states: pending, resolved, rejected. The
onFulfilledcallback will be called when a promise is resolved, or if a promise is already resolved, then theonFulfilledcallback will be called immediately. TheonRejectedcallback will be called when a promise is rejected, or if a promise is already rejected, then theonRejectedcallback will be called immediately.Parameters:
Name Type Argument Description onFulfilledPCCViewer.Promise~onFulfilled <optional> Called if or when the promise is resolved. Optionally pass a value of
nullorundefinedif you do not use this callback.onRejectedPCCViewer.Promise~onRejected <optional> Called if or when the promise is rejected.
Returns:
PCCViewer.Promise A promise object that is resolved according to the Promises/A+ standard.
Example
var viewerControl = $("#myElement").pccViewer(...).viewerControl; // a basic example viewerControl.requestPageText(1).then( function onFulfilled(value) { // according to the definition of requestPageText, the promise will be resolved with the text // of the page. var pageText = value; }, function onRejected(reason) { // according to the definition of requestPageText, the promise will be rejected if there is // an error extracting text for the document. alert("Something went wrong getting the text of page 1. " + reason); } ); // it's OK to pass a value of null (or undefined) for `onFulfilled` viewerControl.requestPageText(1).then( null, function onRejected(reason) { ... } ); // it's OK to ignore the onRejected parameter, or pass null or undefined viewerControl.requestPageText(1).then( function onFulfilled(value) { ... } );
Type Definitions
-
onFulfilled(value)
-
An
onFulfilledcallback is called if or when a PCCViewer.Promise is resolved.Parameters:
Name Type Description value* The type and value of the
valueargument depends on the API method that generated the Promise object. See the documentation for the method that generated the Promise. -
onRejected(reason)
-
An
onRejectedcallback is called if or when a PCCViewer.Promise is rejected.Parameters:
Name Type Description reason* The type and value of the
reasonargument depends on the API method that generated the Promise object. See the documentation for the method that generated the Promise.