當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.PropagateTask類代碼示例

本文整理匯總了TypeScript中@tempest/core.PropagateTask的典型用法代碼示例。如果您正苦於以下問題:TypeScript PropagateTask類的具體用法?TypeScript PropagateTask怎麽用?TypeScript PropagateTask使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PropagateTask類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it ('should end a stream when a signal emits', (done) => {
    const signal = new Stream<number>({
      run (sink: Sink<number>, scheduler: Scheduler) {
        const task = scheduler.delay(90, PropagateTask.event(100, sink))
        return {
          dispose () {
           scheduler.cancel(task)
          }
        }
      }
    })

    const source = new Stream<number>({
      run (sink: Sink<number>, scheduler: Scheduler) {
       const task = scheduler.periodic(50, PropagateTask.event(0, sink))

        return {
          dispose () {
            scheduler.cancel(task)
          }
        }
      }
    })

    const stream = endWhen(signal, source)
    const expected = [0, 0]

    stream.subscribe((x: number) => {
      assert(x === expected.shift())
    }, done, (y) => {
      assert(y === 100)
      done()
    })
  })
開發者ID:TylorS,項目名稱:tempest,代碼行數:34,代碼來源:index.ts

示例2: run

 run (sink: Sink<void>, scheduler: Scheduler): Disposable<void> {
   const task = scheduler.asap(PropagateTask.end(void 0, sink))
   return {
     dispose () {
       scheduler.cancel(task)
     }
   }
 }
開發者ID:TylorS,項目名稱:tempest,代碼行數:8,代碼來源:index.ts

示例3: run

  run (sink: Sink<Error>, scheduler: Scheduler): Disposable<Error> {
    const task = scheduler.asap(PropagateTask.error(this.err, sink))

    return {
      dispose () {
        scheduler.cancel(task)
      }
    }
  }
開發者ID:TylorS,項目名稱:tempest,代碼行數:9,代碼來源:index.ts

示例4: it

  it ('should sample another streams values', function (done) {
    const sampler = new Stream<number>({
      run (sink: Sink<number>, scheduler: Scheduler) {
        scheduler.delay(100, PropagateTask.event(0, sink))
        scheduler.delay(250, PropagateTask.event(0, sink))
        scheduler.delay(260, PropagateTask.end(0, sink))
        return {
          dispose () {
            return void 0
          }
        }
      }
    })

    const stream = new Stream<number>({
      run (sink: Sink<number>, scheduler: Scheduler) {
        sink.event(scheduler.now(), 1)
        setTimeout(() => {
          sink.event(scheduler.now(), 2)
        }, 150)
        setTimeout(() => {
          sink.event(scheduler.now(), 3)
        }, 190)
        return {
          dispose () {
            return void 0
          }
        }
      }
    })

    const expected = [1, 3]

    sample(sampler, stream).subscribe((x: number) => {
      assert(x === expected.shift())
    }, done, (x) => {
      assert(x === 3)
      done()
    })
  })
開發者ID:TylorS,項目名稱:tempest,代碼行數:40,代碼來源:index.ts

示例5: it

  it ('should flatten a higher order stream into a single order stream', (done) => {
    const stream = Stream.of(1, 2, 3)
    const higherStream = new Stream<Stream<number>>({
      run (sink: Sink<Stream<number>>, scheduler: Scheduler) {
        const task = scheduler.asap(PropagateTask.event(stream, sink))
        const task2 = scheduler.asap(PropagateTask.end(void 0, sink))
        return {
          dispose () {
            scheduler.cancel(task)
            scheduler.cancel(task2)
          }
        }
      }
    })

    const s = flatten(higherStream)
    const expected = [1, 2, 3]

    s.subscribe((x) => {
      assert(x === expected.shift())
    }, done, () => done())
  })
開發者ID:TylorS,項目名稱:tempest,代碼行數:22,代碼來源:index.ts

示例6: it

  it ('should allow replacing a stream after an error', (done) => {
    const errorStream = new Stream<any>({
      run (sink: Sink<any>, scheduler: Scheduler) {
        const task = scheduler.asap(PropagateTask.error(new Error('oh no'), sink))
        return {
          dispose () {
            scheduler.cancel(task)
          }
        }
      }
    })

    const replace = (e: Error) => Stream.of(1)

    const stream = replaceError(replace, errorStream)

    stream.subscribe((x: number) => {
      assert(x === 1)
    }, done, () => done())
  })
開發者ID:TylorS,項目名稱:tempest,代碼行數:20,代碼來源:index.ts

示例7: complete

 complete (value?: T) {
   defaultScheduler.asap(PropagateTask.end(value, this.source))
 }
開發者ID:TylorS,項目名稱:tempest,代碼行數:3,代碼來源:index.ts

示例8: error

 error (err: Error) {
   defaultScheduler.asap(PropagateTask.error(err, this.source))
 }
開發者ID:TylorS,項目名稱:tempest,代碼行數:3,代碼來源:index.ts

示例9: next

 next (value: T) {
   defaultScheduler.asap(PropagateTask.event(value, this.source))
 }
開發者ID:TylorS,項目名稱:tempest,代碼行數:3,代碼來源:index.ts


注:本文中的@tempest/core.PropagateTask類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。