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

@agoric/eventual-send

Package Overview
Dependencies
Maintainers
4
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/eventual-send - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

78

dist/eventual-send.cjs.js

@@ -34,10 +34,12 @@ 'use strict';

return Promise.makeHandled(resolve => {
return Promise.makeHandled((resolve, reject) => {
// We run in a future turn to prevent synchronous attacks,
Promise.resolve().then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
);
// with the same unfulfilled handler.
}, unfulfilledHandler);
Promise.resolve()
.then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
)
.catch(reject);
// with the default unfulfilled forwarding handler.
});
}

@@ -49,3 +51,2 @@

}
// When this promise resolves, run the forwarding handler.
return Promise.resolve(p).then(o =>

@@ -107,3 +108,3 @@ forwardingHandler[operation](o, ...args),

let handledReject;
let continueForwarding;
let continueForwarding = () => {};
const handledP = new Promise((resolve, reject) => {

@@ -120,12 +121,21 @@ handledResolve = resolve;

// (too many round-trips), but is an easy way to create a local handled Promise.
const handlerP = new Promise(resolve => {
continueForwarding = () => resolve(null);
const interlockP = new Promise(resolve => {
continueForwarding = () => {
resolve(null);
// Return undefined.
};
});
const postpone = forwardedOperation => {
const makePostpone = postponedOperation => {
// Just wait until the handler is resolved/rejected.
return async (p, ...args) => {
// console.log(`forwarding ${forwardedOperation}`);
await handlerP;
return p[forwardedOperation](...args);
return function postpone(x, ...args) {
// console.log(`forwarding ${postponedOperation}`);
return Promise.makeHandled((resolve, reject) => {
interlockP
.then(() => {
// console.log('postponed', postponedOperation);
resolve(x[postponedOperation](...args));
})
.catch(reject);
});
};

@@ -135,6 +145,6 @@ };

unfulfilledHandler = {
GET: postpone('get'),
PUT: postpone('put'),
DELETE: postpone('delete'),
POST: postpone('post'),
GET: makePostpone('get'),
PUT: makePostpone('put'),
DELETE: makePostpone('delete'),
POST: makePostpone('post'),
};

@@ -154,5 +164,3 @@ }

function rejectHandled(reason) {
if (continueForwarding) {
continueForwarding();
}
continueForwarding();
handledReject(reason);

@@ -169,3 +177,3 @@ }

if (!fulfilledHandler) {
// Resolve with the target.
// Resolve with the target when it's ready.
handledResolve(target);

@@ -176,5 +184,7 @@

// Reuse the unfulfilled handler.
console.log('reusing unfulfilled handler');
promiseToHandler.set(handledP, existingUnfulfilledHandler);
return;
// We don't forward the messages until the target resolves,
// otherwise we'll have an infinite loop of default
// unfulfilledHandlers.
}

@@ -187,3 +197,3 @@

promiseToHandler.set(handledP, existingFulfilledHandler);
return;
return continueForwarding();
}

@@ -193,3 +203,3 @@

promiseToHandler.delete(handledP);
return;
return continueForwarding();
}

@@ -223,14 +233,12 @@

handledResolve(presence);
// Tell the default unfulfilledHandler to forward messages.
if (continueForwarding) {
continueForwarding();
}
} catch (e) {
rejectHandled(e);
handledReject(e);
}
return continueForwarding();
}
// Invoke the callback to let the user resolve/reject.
executor(resolveHandled, rejectHandled);
executor((...args) => {
resolveHandled(...args);
}, rejectHandled);

@@ -237,0 +245,0 @@ // Return a handled Promise, which wil be resolved/rejected

@@ -32,10 +32,12 @@ /**

return Promise.makeHandled(resolve => {
return Promise.makeHandled((resolve, reject) => {
// We run in a future turn to prevent synchronous attacks,
Promise.resolve().then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
);
// with the same unfulfilled handler.
}, unfulfilledHandler);
Promise.resolve()
.then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
)
.catch(reject);
// with the default unfulfilled forwarding handler.
});
}

@@ -47,3 +49,2 @@

}
// When this promise resolves, run the forwarding handler.
return Promise.resolve(p).then(o =>

@@ -105,3 +106,3 @@ forwardingHandler[operation](o, ...args),

let handledReject;
let continueForwarding;
let continueForwarding = () => {};
const handledP = new Promise((resolve, reject) => {

@@ -118,12 +119,21 @@ handledResolve = resolve;

// (too many round-trips), but is an easy way to create a local handled Promise.
const handlerP = new Promise(resolve => {
continueForwarding = () => resolve(null);
const interlockP = new Promise(resolve => {
continueForwarding = () => {
resolve(null);
// Return undefined.
};
});
const postpone = forwardedOperation => {
const makePostpone = postponedOperation => {
// Just wait until the handler is resolved/rejected.
return async (p, ...args) => {
// console.log(`forwarding ${forwardedOperation}`);
await handlerP;
return p[forwardedOperation](...args);
return function postpone(x, ...args) {
// console.log(`forwarding ${postponedOperation}`);
return Promise.makeHandled((resolve, reject) => {
interlockP
.then(() => {
// console.log('postponed', postponedOperation);
resolve(x[postponedOperation](...args));
})
.catch(reject);
});
};

@@ -133,6 +143,6 @@ };

unfulfilledHandler = {
GET: postpone('get'),
PUT: postpone('put'),
DELETE: postpone('delete'),
POST: postpone('post'),
GET: makePostpone('get'),
PUT: makePostpone('put'),
DELETE: makePostpone('delete'),
POST: makePostpone('post'),
};

@@ -152,5 +162,3 @@ }

function rejectHandled(reason) {
if (continueForwarding) {
continueForwarding();
}
continueForwarding();
handledReject(reason);

@@ -167,3 +175,3 @@ }

if (!fulfilledHandler) {
// Resolve with the target.
// Resolve with the target when it's ready.
handledResolve(target);

@@ -174,5 +182,7 @@

// Reuse the unfulfilled handler.
console.log('reusing unfulfilled handler');
promiseToHandler.set(handledP, existingUnfulfilledHandler);
return;
// We don't forward the messages until the target resolves,
// otherwise we'll have an infinite loop of default
// unfulfilledHandlers.
}

@@ -185,3 +195,3 @@

promiseToHandler.set(handledP, existingFulfilledHandler);
return;
return continueForwarding();
}

@@ -191,3 +201,3 @@

promiseToHandler.delete(handledP);
return;
return continueForwarding();
}

@@ -221,14 +231,12 @@

handledResolve(presence);
// Tell the default unfulfilledHandler to forward messages.
if (continueForwarding) {
continueForwarding();
}
} catch (e) {
rejectHandled(e);
handledReject(e);
}
return continueForwarding();
}
// Invoke the callback to let the user resolve/reject.
executor(resolveHandled, rejectHandled);
executor((...args) => {
resolveHandled(...args);
}, rejectHandled);

@@ -235,0 +243,0 @@ // Return a handled Promise, which wil be resolved/rejected

@@ -38,10 +38,12 @@ (function (global, factory) {

return Promise.makeHandled(resolve => {
return Promise.makeHandled((resolve, reject) => {
// We run in a future turn to prevent synchronous attacks,
Promise.resolve().then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
);
// with the same unfulfilled handler.
}, unfulfilledHandler);
Promise.resolve()
.then(() =>
// and resolve to the answer from the unfulfilled handler,
resolve(unfulfilledHandler[operation](p, ...args)),
)
.catch(reject);
// with the default unfulfilled forwarding handler.
});
}

@@ -53,3 +55,2 @@

}
// When this promise resolves, run the forwarding handler.
return Promise.resolve(p).then(o =>

@@ -111,3 +112,3 @@ forwardingHandler[operation](o, ...args),

let handledReject;
let continueForwarding;
let continueForwarding = () => {};
const handledP = new Promise((resolve, reject) => {

@@ -124,12 +125,21 @@ handledResolve = resolve;

// (too many round-trips), but is an easy way to create a local handled Promise.
const handlerP = new Promise(resolve => {
continueForwarding = () => resolve(null);
const interlockP = new Promise(resolve => {
continueForwarding = () => {
resolve(null);
// Return undefined.
};
});
const postpone = forwardedOperation => {
const makePostpone = postponedOperation => {
// Just wait until the handler is resolved/rejected.
return async (p, ...args) => {
// console.log(`forwarding ${forwardedOperation}`);
await handlerP;
return p[forwardedOperation](...args);
return function postpone(x, ...args) {
// console.log(`forwarding ${postponedOperation}`);
return Promise.makeHandled((resolve, reject) => {
interlockP
.then(() => {
// console.log('postponed', postponedOperation);
resolve(x[postponedOperation](...args));
})
.catch(reject);
});
};

@@ -139,6 +149,6 @@ };

unfulfilledHandler = {
GET: postpone('get'),
PUT: postpone('put'),
DELETE: postpone('delete'),
POST: postpone('post'),
GET: makePostpone('get'),
PUT: makePostpone('put'),
DELETE: makePostpone('delete'),
POST: makePostpone('post'),
};

@@ -158,5 +168,3 @@ }

function rejectHandled(reason) {
if (continueForwarding) {
continueForwarding();
}
continueForwarding();
handledReject(reason);

@@ -173,3 +181,3 @@ }

if (!fulfilledHandler) {
// Resolve with the target.
// Resolve with the target when it's ready.
handledResolve(target);

@@ -180,5 +188,7 @@

// Reuse the unfulfilled handler.
console.log('reusing unfulfilled handler');
promiseToHandler.set(handledP, existingUnfulfilledHandler);
return;
// We don't forward the messages until the target resolves,
// otherwise we'll have an infinite loop of default
// unfulfilledHandlers.
}

@@ -191,3 +201,3 @@

promiseToHandler.set(handledP, existingFulfilledHandler);
return;
return continueForwarding();
}

@@ -197,3 +207,3 @@

promiseToHandler.delete(handledP);
return;
return continueForwarding();
}

@@ -227,14 +237,12 @@

handledResolve(presence);
// Tell the default unfulfilledHandler to forward messages.
if (continueForwarding) {
continueForwarding();
}
} catch (e) {
rejectHandled(e);
handledReject(e);
}
return continueForwarding();
}
// Invoke the callback to let the user resolve/reject.
executor(resolveHandled, rejectHandled);
executor((...args) => {
resolveHandled(...args);
}, rejectHandled);

@@ -241,0 +249,0 @@ // Return a handled Promise, which wil be resolved/rejected

{
"name": "@agoric/eventual-send",
"version": "0.2.0",
"version": "0.2.1",
"description": "Extend a Promise class to implement the eventual-send API",

@@ -5,0 +5,0 @@ "main": "dist/eventual-send.cjs.js",

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