Skip to content

Commit c56c35b

Browse files
committed
Default callbacks to noop
1 parent 3750258 commit c56c35b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/Model.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReplicateError, ReplicateResponseError } from "./errors.js";
22
import Prediction from "./Prediction.js";
33
import ReplicateObject from "./ReplicateObject.js";
4-
import { sleep } from "./utils.js";
4+
import { noop, sleep } from "./utils.js";
55

66
export default class Model extends ReplicateObject {
77
static propertyMap = {
@@ -48,7 +48,7 @@ export default class Model extends ReplicateObject {
4848

4949
async predict(
5050
input,
51-
{ onUpdate, onTemporaryError } = {},
51+
{ onUpdate = noop, onTemporaryError = noop } = {},
5252
{
5353
defaultPollingInterval = 500,
5454
backoffFn = (errorCount) => Math.pow(2, errorCount) * 100,
@@ -60,7 +60,7 @@ export default class Model extends ReplicateObject {
6060

6161
let prediction = await this.createPrediction(input);
6262

63-
onUpdate && onUpdate(prediction);
63+
onUpdate(prediction);
6464

6565
let pollingInterval = defaultPollingInterval;
6666
let errorCount = 0;
@@ -72,7 +72,7 @@ export default class Model extends ReplicateObject {
7272
try {
7373
prediction = await this.client.prediction(prediction.id).load();
7474

75-
onUpdate && onUpdate(prediction);
75+
onUpdate(prediction);
7676

7777
errorCount = 0; // Reset because we've had a non-error response.
7878
} catch (err) {
@@ -89,7 +89,7 @@ export default class Model extends ReplicateObject {
8989

9090
errorCount += 1;
9191

92-
onTemporaryError && onTemporaryError(err);
92+
onTemporaryError(err);
9393

9494
pollingInterval = backoffFn(errorCount);
9595
}

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export function noop() {}
2+
13
export function sleep(ms) {
24
return new Promise((resolve) => {
35
setTimeout(resolve, ms);

0 commit comments

Comments
 (0)