Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The following is a curated list of changes in the Enact project, newest changes on the top.

## [unreleased]

### Added

- `webos/LS2Request.sendLS2Request` to provide LS2Request.send method with Promise

## [4.9.0-beta.1] - 2024-06-17

No significant changes.
Expand Down
50 changes: 50 additions & 0 deletions packages/webos/LS2Request/LS2Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,53 @@ export default class LS2Request {
}
}
}

/**
* Provides a Promise which calls LS2Request.send to give onSuccess and onFailure as callback functions of Promise methods.
*
* Usage:
* ```
* sendLS2Request(options).then(onSuccess, onFailure);
* ```
*
* @function
* @memberof webos/LS2Request
* @param {Object} options Options for the LS2 Request call except onSuccess and onFailure.
* @param {String} options.service The name of the LS2 service.
* @param {String} options.method The name of the method.
* @param {Object} options.parameters Any parameters required by the service method.
* @param {Function} options.onComplete The handler to run when the request
* is completed, regardless of return status.
* @param {Function} options.onTimeout The handler to run when the request
* times out. Used in conjunction with `timeout`.
* @param {Boolean} options.subscribe Subscribe to service methods that support subscription.
* @param {Number} options.timeout The delay in milliseconds to wait for the request to return.
* @returns {Promise} Promise which runs LS2Request.send
* @public
*/
export const sendLS2Request = ({
service = '',
method = '',
parameters = {},
onComplete = null,
onTimeout = timeoutHandler,
subscribe = false,
timeout = 0
}) => {
return new Promise((resolve, reject) => {
new LS2Request().send({
service,
method,
parameters,
onSuccess: resolve,
onFailure: result => {
failureHandler(result);
reject(result);
},
onComplete,
onTimeout,
subscribe,
timeout
});
});
};