Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@endo/promise-kit

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endo/promise-kit - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

24

package.json
{
"name": "@endo/promise-kit",
"version": "1.1.2",
"version": "1.1.3",
"description": "Helper for making promises",

@@ -29,4 +29,4 @@ "keywords": [

"build": "exit 0",
"build:types": "tsc --build tsconfig.build.json",
"clean:types": "git clean -f '*.d.ts*'",
"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"cover": "c8 ava",

@@ -42,8 +42,7 @@ "lint": "yarn lint:types && yarn lint:eslint",

"dependencies": {
"ses": "^1.5.0"
"ses": "^1.6.0"
},
"devDependencies": {
"@types/node": "^16.6.0",
"ava": "^6.1.2",
"babel-eslint": "^10.0.3",
"ava": "^6.1.3",
"babel-eslint": "^10.1.0",
"c8": "^7.14.0",

@@ -53,6 +52,6 @@ "eslint": "^8.57.0",

"eslint-config-prettier": "^9.1.0",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"prettier": "^3.2.5",
"typescript": "~5.5.0-dev.20240327"
"typescript": "5.5.2"
},

@@ -76,3 +75,4 @@ "files": [

"files": [
"test/**/test-*.js"
"test/**/test-*.*",
"test/**/*.test.*"
],

@@ -87,3 +87,3 @@ "timeout": "2m"

},
"gitHead": "08e59bc0d262565165636c2e3875bbe3dcb91cf8"
"gitHead": "681b813ccb1fa177905dabf2ed3f5f248cb33ce7"
}
# Promise Kit
A helper for making promises
The promise-kit package provides a simple abstraction for creating and managing a promise. It exports, `makePromiseKit` which is a utility function used to create a Promise and its associated resolver and rejector functions. This is particularly useful in asynchronous programming, where you might need to create a promise and resolve or reject it at a later point in time.
Note that this serves as a "ponyfill" for `Promise.withResolvers`, making certain accommodations to ensure that the resulting promises can pipeline messages through `@endo/eventual-send`.
## Usage
Here’s an example of how `makePromiseKit` might be used in an Agoric smart contract or JavaScript program:
### Basic Example
```javascript
import { makePromiseKit } from '@endo/promise-kit';
function asyncOperation() {
const { promise, resolve, reject } = makePromiseKit();
setTimeout(() => {
const success = true; // Simulating success or failure
if (success) {
resolve("Operation successful!");
} else {
reject("Operation failed!");
}
}, 2000);
return promise;
}
async function handleAsyncOperation() {
try {
const result = await asyncOperation();
console.log(result); // "Operation successful!"
} catch (error) {
console.error(error); // "Operation failed!"
}
}
handleAsyncOperation();
```
### Creating Multiple Promise Kits
You can create multiple promise kits for managing various asynchronous tasks.
```javascript
const kit1 = makePromiseKit();
const kit2 = makePromiseKit();
kit1.promise.then(value => console.log('Kit 1 resolved with:', value));
kit2.promise.then(value => console.log('Kit 2 resolved with:', value));
kit1.resolve('First success');
kit2.resolve('Second success');
```
## API
### `makePromiseKit()`
Creates a new promise kit.
**Returns**
- **`promise`**: The promise object.
- **`resolve`**: The resolve function for the promise.
- **`reject`**: The reject function for the promise.
## Links
[Repository](https://github.com/endojs/endo/tree/master/packages/promise-kit)
## License
This package is licensed under the Apache-2.0 License.

@@ -7,3 +7,3 @@ export function makeReleasingExecutorKit<T>(): Pick<import("./types.js").PromiseKit<T>, "resolve" | "reject"> & {

*/
export type PromiseExecutor<T> = (resolve: (value: import('./types.js').ERef<T>) => void, reject: (reason: any) => void) => any;
export type PromiseExecutor<T> = (resolve: (value: import("./types.js").ERef<T>) => void, reject: (reason: any) => void) => any;
//# sourceMappingURL=promise-executor-kit.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc