当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript thunk.promise方法代码示例

本文整理汇总了TypeScript中thunks.thunk.promise方法的典型用法代码示例。如果您正苦于以下问题:TypeScript thunk.promise方法的具体用法?TypeScript thunk.promise怎么用?TypeScript thunk.promise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thunks.thunk的用法示例。


在下文中一共展示了thunk.promise方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

      it(`with bytes ${bytes}`, async function () {
        this.timeout(1000 * 20)

        const server = echoServer()
        await server.listen(0)

        const cli1 = new Client()
        cli1.on('error', (err) => { ilog(Object.assign(err, { class: 'client error' })) })

        await cli1.connect(server.address().port)

        const stream1 = cli1.request()
        stream1.on('error', (err) => { throw Object.assign(err, { class: 'client stream error' })})
        const dataStream1 = new RandDataStream(bytes)
        stream1.on('drain', () => {
          dataStream1.resume()
        })
        // randDataStream.pipe(stream) // use paused mode for large stream
        dataStream1
          .on('data', (chunk) => {
            if (!stream1.write(chunk)) {
              dataStream1.pause()
            }
          })
          .on('end', () => stream1.end())

        const hash1 = createHash('sha256')
        stream1.pipe(hash1)

        const cli2 = await cli1.spawn(server.address().port)
        const stream2 = cli2.request()
        const stream3 = cli2.request()
        stream2.on('error', (err) => { throw Object.assign(err, { class: 'client stream error' })})
        stream3.on('error', (err) => { throw Object.assign(err, { class: 'client stream error' })})
        const dataStream2 = new RandDataStream(bytes)
        stream3.on('drain', () => {
          dataStream2.resume()
        })
        dataStream2
          .on('data', (chunk) => {
            stream2.write(chunk)
            if (!stream3.write(chunk)) {
              dataStream2.pause()
            }
          })
          .on('end', () => {
            stream2.end()
            stream3.end()
          })

        const hash2 = createHash('sha256')
        stream2.pipe(hash2)
        const hash3 = createHash('sha256')
        stream3.pipe(hash3)

        await Promise.all([
          onceEmit.call(stream1, 'end'),
          onceEmit.call(stream2, 'end'),
          onceEmit.call(stream3, 'end'),
        ])

        equal(dataStream1.readBytes, bytes)
        equal(dataStream1.totalSize, bytes)
        equal(stream1.bytesRead, bytes)
        equal(stream1.bytesWritten, bytes)
        const ret1 = hash1.read() as Buffer
        equal(ret1.toString('hex'), dataStream1.sum)

        equal(dataStream2.readBytes, bytes)
        equal(dataStream2.totalSize, bytes)
        equal(stream2.bytesRead, bytes)
        equal(stream2.bytesWritten, bytes)
        const ret2 = hash2.read() as Buffer
        equal(ret2.toString('hex'), dataStream2.sum)

        equal(stream3.bytesRead, bytes)
        equal(stream3.bytesWritten, bytes)
        const ret3 = hash3.read() as Buffer
        equal(ret3.toString('hex'), dataStream2.sum)

        await Promise.all([cli1.close(), cli2.close()])
        await server.close()
        await thunk.promise(thunk.delay(500))
      })
开发者ID:toajs,项目名称:quic,代码行数:84,代码来源:chaos.ts


注:本文中的thunks.thunk.promise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。