Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/dapi/TokenedDataApi.ts4
-rw-r--r--src/types/misc.d.ts10
2 files changed, 12 insertions, 2 deletions
diff --git a/src/server/dapi/TokenedDataApi.ts b/src/server/dapi/TokenedDataApi.ts
index 5059994..3e0c68c 100644
--- a/src/server/dapi/TokenedDataApi.ts
+++ b/src/server/dapi/TokenedDataApi.ts
@@ -79,7 +79,7 @@ export class TokenedDataApi implements DataApi
*/
request(
data: DataApiInput,
- callback: ( e: Error | null, data: DataApiResult | null ) => void,
+ callback: NodeCallback<DataApiResult>,
id: string
): this
{
@@ -144,7 +144,7 @@ export class TokenedDataApi implements DataApi
private _replyUnlessStale(
newtok: Token<TokenState.DONE>,
resp_data: DataApiResult,
- callback: ( e: Error | null, data: DataApiResult | null ) => void,
+ callback: NodeCallback<DataApiResult>,
id: string
): void
{
diff --git a/src/types/misc.d.ts b/src/types/misc.d.ts
index 6560f2b..83b11b5 100644
--- a/src/types/misc.d.ts
+++ b/src/types/misc.d.ts
@@ -44,3 +44,13 @@ type NominalType<K, T> = K & { __nominal_type__: T };
* Number of seconds since the Unix epoch (1970-01-01 UTC).
*/
type UnixTimestamp = NominalType<number, 'UnixTimestamp'>;
+
+
+/**
+ * Oldschool NodeJS callback
+ *
+ * We should migrate to promises over time. The purpose of this type is to
+ * reduce the boilerplate of these function definitions, and to clearly
+ * document that this pattern is something that used to be done frequently.
+ */
+type NodeCallback<T, R = void> = ( e: Error | null, result: T | null ) => R;