Constructor
new (require("core/pending"))(pendingKeyopt) → {Promise}
- Description:
 Request a new pendingPromise for later resolution.
When the action you are performing is complete, simply call resolve on the returned Promise.
- Source:
 
Example
import Pending from 'core/pending';
import {getString} from 'core/str';
const stringPromise = new Pending('mod_myexample/setup');
const myString = getString('ok')
    .then(okay => {
        window.console.log(okay);
    })
    .then(okay => stringPromise.resolve(okay));
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
pendingKey | 
            
            String | 
                
                    <optional> | 
            
            
                
                
                    'pendingPromise'
                
                 | 
            
            An identifier to help in debugging  | 
        
Returns:
A Native Promise
- Type
 - Promise
 
Methods
(static) Promise(fn, pendingKeyopt) → {Promise}
- Description:
 Create a new Pending Promise with the same interface as a native Promise.
- Source:
 - Since:
 - Moodle 4.2
 
Example
// Use the Pending class in the same way that you would a Native Promise.
import Pending from 'core/pending';
import {getString} from 'core/str';
export const init => {
    Pending.Promise((resolve, reject) => {
        getString('ok')
            .then(okay => {
                window.console.log(okay);
                return okay;
            })
            .then(resolve)
            .catch(reject);
    }, 'mod_myexample/setup:init');
};
    Parameters:
| Name | Type | Attributes | Default | Description | 
|---|---|---|---|---|
fn | 
            
            Callable | A callable which takes the resolve and reject arguments as in a Native Promise constructor.  | 
        ||
pendingKey | 
            
            String | 
                
                    <optional> | 
            
            
                
                
                    'pendingPromise'
                
                 | 
            
            An identifier to help in debugging  | 
        
Returns:
- Type
 - Promise
 
(static) request(pendingKey) → {Promise}
- Description:
 Create a new Pending Promise statically.
- Source:
 - Deprecated:
 - since Moodle 4.2
 
Parameters:
| Name | Type | Description | 
|---|---|---|
pendingKey | 
            
            String | An identifier to help in debugging  | 
        
Returns:
A Native Promise
- Type
 - Promise