Skip to content

Commit

Permalink
feat: 🎸 put back checkUntilChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
hcfw007 committed Dec 12, 2023
1 parent 8f3252b commit e6fc016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pure-functions/retry-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ function getRetryPolicy (): RetryPolicy {
return policy
}

const checkUntilChanged = async (gapMilliseconds: number, maxRetry: number, judgement: () => Promise<boolean> | boolean): Promise<boolean> => {
let changed = await judgement()
let currentTry = 1
while (!changed && (currentTry < maxRetry)) {
await new Promise(resolve => setTimeout(resolve, gapMilliseconds))
changed = await judgement()
currentTry++
}
return changed
}

export {
retryPolicy,
checkUntilChanged,
}
1 change: 1 addition & 0 deletions src/wechaty-mixins/puppet-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {

import type { GErrorMixin } from './gerror-mixin.js'
import type { IoMixin } from './io-mixin.js'
import { checkUntilChanged } from '../pure-functions/retry-policy.js'

const PUPPET_MEMORY_NAME = 'puppet'

Expand Down

0 comments on commit e6fc016

Please sign in to comment.