Merge pull request #40 from cjh980402/main

Remove useless Promise and function code
This commit is contained in:
Killer069 2021-09-04 17:23:49 +05:30 committed by GitHub
commit 7ed401df85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 21 deletions

View File

@ -89,20 +89,18 @@ export class LiveStreaming{
if(Number(segment.split('sq/')[1].split('/')[0]) !== this.packet_count){
continue
}
await (async () => {
return new Promise(async (resolve, reject) => {
let stream = got.stream(this.base_url + segment)
this.request = stream
stream.on('data', (chunk: any) => this.stream.write(chunk))
stream.on('end', () => {
this.packet_count++
resolve('')
})
stream.once('error', (err) => {
this.stream.emit('error', err)
})
await new Promise((resolve, reject) => {
let stream = got.stream(this.base_url + segment)
this.request = stream
stream.on('data', (chunk: any) => this.stream.write(chunk))
stream.on('end', () => {
this.packet_count++
resolve('')
})
})()
stream.once('error', (err) => {
this.stream.emit('error', err)
})
})
}
this.timer = setTimeout(() => {
this.start()

View File

@ -1,11 +1,9 @@
import got, { OptionsOfTextResponseBody } from 'got/dist/source'
export async function url_get (url : string, options? : OptionsOfTextResponseBody) : Promise<string>{
return new Promise(async(resolve, reject) => {
let response = await got(url, options)
if(response.statusCode === 200) {
resolve(response.body)
}
else reject(`Got ${response.statusCode} from ${url}`)
})
}
let response = await got(url, options)
if(response.statusCode === 200) {
return response.body
}
else throw new Error(`Got ${response.statusCode} from ${url}`)
}