-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 7192-oracle-error
- Loading branch information
Showing
39 changed files
with
1,008 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// @ts-check | ||
import { E } from '@endo/far'; | ||
|
||
/** | ||
* @template {(...args: unknown[]) => any} I | ||
* @typedef {import('./types').Callback<I>} Callback | ||
*/ | ||
|
||
/** | ||
* @template {(...args: unknown[]) => any} I | ||
* @typedef {import('./types').SyncCallback<I>} SyncCallback | ||
*/ | ||
|
||
/** | ||
* Synchronously call a callback. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @param {SyncCallback<I>} callback | ||
* @param {Parameters<I>} args | ||
* @returns {ReturnType<I>} | ||
*/ | ||
export const callSync = (callback, ...args) => { | ||
const { target, method, bound } = callback; | ||
if (method === undefined) { | ||
return target(...bound, ...args); | ||
} | ||
return target[method](...bound, ...args); | ||
}; | ||
|
||
/** | ||
* Eventual send to a callback. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @param {Callback<I>} callback | ||
* @param {Parameters<I>} args | ||
* @returns {Promise<Awaited<ReturnType<I>>>} | ||
*/ | ||
export const callE = (callback, ...args) => { | ||
const { target, method, bound } = callback; | ||
if (method === undefined) { | ||
return E(target)(...bound, ...args); | ||
} | ||
return E(target)[method](...bound, ...args); | ||
}; | ||
|
||
/** | ||
* Create a callback from a near function. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @template {(...args: [...B, ...Parameters<I>]) => ReturnType<I>} [T=I] | ||
* @template {unknown[]} [B=[]] | ||
* @param {T} target | ||
* @param {B} bound | ||
* @returns {SyncCallback<I>} | ||
*/ | ||
export const makeSyncFunctionCallback = (target, ...bound) => { | ||
/** @type {unknown} */ | ||
const cb = harden({ target, bound }); | ||
return /** @type {SyncCallback<I>} */ (cb); | ||
}; | ||
harden(makeSyncFunctionCallback); | ||
|
||
/** | ||
* Create a callback from a potentially far function. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @template {import('@endo/far').ERef< | ||
* (...args: [...B, ...Parameters<I>]) => ReturnType<I> | ||
* >} [T=import('@endo/far').ERef<I>] | ||
* @template {unknown[]} [B=[]] | ||
* @param {T} target | ||
* @param {B} bound | ||
* @returns {Callback<I>} | ||
*/ | ||
export const makeFunctionCallback = (target, ...bound) => { | ||
/** @type {unknown} */ | ||
const cb = harden({ target, bound }); | ||
return /** @type {Callback<I>} */ (cb); | ||
}; | ||
harden(makeFunctionCallback); | ||
|
||
/** | ||
* Create a callback from a near method. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @template {PropertyKey} P | ||
* @template {{ | ||
* [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I> | ||
* }} [T={ [x in P]: I }] | ||
* @template {unknown[]} [B=[]] | ||
* @param {T} target | ||
* @param {P} methodName | ||
* @param {B} bound | ||
* @returns {SyncCallback<I>} | ||
*/ | ||
export const makeSyncMethodCallback = (target, methodName, ...bound) => { | ||
/** @type {unknown} */ | ||
const cb = harden({ target, method: methodName, bound }); | ||
return /** @type {SyncCallback<I>} */ (cb); | ||
}; | ||
harden(makeSyncMethodCallback); | ||
|
||
/** | ||
* Create a callback from a potentially far method. | ||
* | ||
* @template {(...args: unknown[]) => any} I | ||
* @template {PropertyKey} P | ||
* @template {import('@endo/far').ERef<{ | ||
* [x in P]: (...args: [...B, ...Parameters<I>]) => ReturnType<I> | ||
* }>} [T=import('@endo/far').ERef<{ [x in P]: I }>] | ||
* @template {unknown[]} [B=[]] | ||
* @param {T} target | ||
* @param {P} methodName | ||
* @param {B} bound | ||
* @returns {Callback<I>} | ||
*/ | ||
export const makeMethodCallback = (target, methodName, ...bound) => { | ||
/** @type {unknown} */ | ||
const cb = harden({ target, method: methodName, bound }); | ||
return /** @type {Callback<I>} */ (cb); | ||
}; | ||
harden(makeMethodCallback); |
Oops, something went wrong.