Skip to content

Commit

Permalink
documents index.js interface
Browse files Browse the repository at this point in the history
  • Loading branch information
meschbach committed Jul 25, 2024
1 parent 3c0e557 commit 958bdd4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
declare module "junk-bucket" {
/**
* An adapter from the standard (error, result) NodeJS callback style.
*
* At this point you should probably prefer to use the builtin node promises for the callbacks. Still useful for
* wrapping external libraries who do not yet have callbacks.
*
* @callback wrap Accepts a callback to interpret the success/callback of the NodeJS style
* @returns a promise to be resolved when the callback passed to perform function resolves.
*/
export function es6_node<T>(wrap: (err: any, value: T) => void): Promise<T>;

/**
* nope - does nothing. literally.
*/
export function nope(): void;

interface Logger {
log(...args: any[]): void;

error(...args: any[]): void;
}

/**
* Wraps the given operation and logs failures of the promise. This is primarily intended to provide async entry points
* to avoid having to re-write the this for every command
*
* @param perform An async function to be resolved or logged
* @param logger Logger to be passed to the performer and target when the application fails
*/
function main(perform: (logger: Logger) => Promise<any>, logger ?: Logger);
}
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
/**
* An adapter from the standard (error, result) NodeJS callback style.
*
* At this point you should probably prefer to use the builtin node promises for the callbacks. Still useful for
* wrapping external libraries who do not yet have callbacks.
*
* @callback perform Accepts a callback to interpret the success/callback of the NodeJS style
* @returns a promise to be resolved when the callback passed to perform function resolves.
*/
function es6_node( perform ) {
return new Promise( ( accept, reject ) => {
try {
perform( ( error, result ) => {
perform( ( error, result ) => {
if( error ) {
reject( error )
} else {
Expand Down

0 comments on commit 958bdd4

Please sign in to comment.