提问人:rudeTool 提问时间:8/31/2023 更新时间:8/31/2023 访问量:32
递归在 NodeJS TypeScript 异步方法中无法正常工作
recursion not working properly in nodejs typescript async method
问:
我在 nodejs 中有一个异步方法,我试图将 api 调用限制在一定限制以上,这是我的代码:
async initializeVideo() {
console.log(this.transcodingRetryCounter)
if (this.transcodingRetryCounter >= this.transcodingRetryLimit) {
console.log('Transcoding Retry limit reached,Stopping the transcoding');
return;
}
this.player = videojs(
this.$refs.videoPlayer,
this.options,
function onPlayerReady() {
console.log('Playing on transcoded video')
}
)
this.player.on('error', () => {
console.log('error')
console.log(this.player.error())
this.transcodingStatus = TRANSCODING_STATUS.REMAINING
this.transcodingRetryCounter++;
this.initializeVideo()
VideoService.checkTranscodingError(this.$route.params.id)
})
this.player.ready(() => {
console.log('ready hu') // not going inside usage
this.player.tech().on('usage', e => {. // I am not reaching inside.
if (e.name === 'vhs-rendition-blacklisted') {
console.log('usage hu')
this.transcodingStatus = TRANSCODING_STATUS.REMAINING
this.transcodingRetryCounter++;
this.initializeVideo()
this.player.play()
VideoService.checkTranscodingError(this.$route.params.id)
}
})
})
if (this.transcodingStatus !== TRANSCODING_STATUS.COMPLETED) {
this.player.src({
type: 'video/mp4',
src: this.src
})
console.log('Playing video directly from bucket')
}
this.player.hlsQualitySelector = videojsqualityselector
this.player.hlsQualitySelector({
displayCurrentQuality: true
})
}
首先使用以下方法将 transcodingRetryCounter 设置为 0,transcodingRetryLimit 设置为 3:
data() {
return {
player: null,
transcodingRetryLimit: 3,
transcodingRetryCounter: 0
}
}
但是当我使用计数器打印计数器时,它会一直持续到 6 点,然后停止,即使它停止在 3 点。console.log(transcodingRetryCounter)
这里有什么问题?
答: 暂无答案
评论