1
1
import { ReplicateError , ReplicateResponseError } from "./errors.js" ;
2
2
import Prediction from "./Prediction.js" ;
3
3
import ReplicateObject from "./ReplicateObject.js" ;
4
- import { sleep } from "./utils.js" ;
4
+ import { noop , sleep } from "./utils.js" ;
5
5
6
6
export default class Model extends ReplicateObject {
7
7
static propertyMap = {
@@ -48,7 +48,7 @@ export default class Model extends ReplicateObject {
48
48
49
49
async predict (
50
50
input ,
51
- { onUpdate, onTemporaryError } = { } ,
51
+ { onUpdate = noop , onTemporaryError = noop } = { } ,
52
52
{
53
53
defaultPollingInterval = 500 ,
54
54
backoffFn = ( errorCount ) => Math . pow ( 2 , errorCount ) * 100 ,
@@ -60,7 +60,7 @@ export default class Model extends ReplicateObject {
60
60
61
61
let prediction = await this . createPrediction ( input ) ;
62
62
63
- onUpdate && onUpdate ( prediction ) ;
63
+ onUpdate ( prediction ) ;
64
64
65
65
let pollingInterval = defaultPollingInterval ;
66
66
let errorCount = 0 ;
@@ -72,7 +72,7 @@ export default class Model extends ReplicateObject {
72
72
try {
73
73
prediction = await this . client . prediction ( prediction . id ) . load ( ) ;
74
74
75
- onUpdate && onUpdate ( prediction ) ;
75
+ onUpdate ( prediction ) ;
76
76
77
77
errorCount = 0 ; // Reset because we've had a non-error response.
78
78
} catch ( err ) {
@@ -89,7 +89,7 @@ export default class Model extends ReplicateObject {
89
89
90
90
errorCount += 1 ;
91
91
92
- onTemporaryError && onTemporaryError ( err ) ;
92
+ onTemporaryError ( err ) ;
93
93
94
94
pollingInterval = backoffFn ( errorCount ) ;
95
95
}
0 commit comments