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


TypeScript timers.setTimeout函数代码示例

本文整理汇总了TypeScript中timers.setTimeout函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setTimeout函数的具体用法?TypeScript setTimeout怎么用?TypeScript setTimeout使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: searchLessons

export function searchLessons(req: Request, res: Response) {

    const queryParams = req.query;

    const courseId = queryParams.courseId,
          filter = queryParams.filter || '',
          sortOrder = queryParams.sortOrder || 'asc',
          pageNumber = parseInt(queryParams.pageNumber) || 0,
          pageSize = parseInt(queryParams.pageSize) || 3;

    let lessons = Object.values(LESSONS).filter(lesson => lesson.courseId == courseId).sort((l1, l2) => l1.id - l2.id);

    if (filter) {
       lessons = lessons.filter(lesson => lesson.description.trim().toLowerCase().search(filter.toLowerCase()) >= 0);
    }

    if (sortOrder == "desc") {
        lessons = lessons.reverse();
    }

    const initialPos = pageNumber * pageSize;

    const lessonsPage = lessons.slice(initialPos, initialPos + pageSize);

    setTimeout(() => {
        res.status(200).json({payload: lessonsPage});
    },1000);


}
开发者ID:mrplanktonlex,项目名称:rxjs-course,代码行数:30,代码来源:search-lessons.route.ts

示例2: runLoader

 public runLoader(nameLoader) {
     this.loaderService.registeredLoaders[nameLoader].activate();
     let that = this;
     setTimeout(() => {
       that.loaderService.registeredLoaders[nameLoader].deactivate();
     }, 2000);
 }
开发者ID:onap-sdc,项目名称:sdc-ui,代码行数:7,代码来源:multiple-second-loader-example.component.ts

示例3: testChangeHashEvent

 public testChangeHashEvent() {
     let windowBuilder = this.getWindowBuilder();
     let window = windowBuilder.setLocation("http://example.com").getMock();
     let callsCounter = this.createCallsCounter();
     window.addEventListener("hashchange", () => {
         callsCounter.call();
     });
     window.location.hash = "#foo1";
     window.location.hash = "#foo2";
     window.dispatchEvent(new HashChangeEvent("hashchange"));
     setTimeout(() => {
         this.assertSame(3, callsCounter.getCounter());
     }, 100);
 }
开发者ID:FreeElephants,项目名称:TSxUnit,代码行数:14,代码来源:WindowBuilderTest.ts

示例4: function

    return function() {
      let now = +new Date()

      if (!previous) previous = now

      if (now - previous > atleast) {
        fn()
        // 重置上一次开始时间为本次结束时间
        previous = now
      } else {
        clearTimeout(timer)
        timer = setTimeout(function() {
          fn()
        }, delay)
      }
    }
开发者ID:stefaniepei,项目名称:react-redux-scaffold,代码行数:16,代码来源:index.ts

示例5: interval

  protected async interval() {
    clearTimeout(this.timeouts.betsInterval);

    try {
      const _modifiedAt = await global.db.engine.findOne(global.systems.bets.collection.data, { key: 'betsModifiedTime' });
      if (this.modifiedAt !== _modifiedAt) {
        this.modifiedAt = _modifiedAt;
        this.currentBet = await global.db.engine.findOne(global.systems.bets.collection.data, { key: 'bets' });
        this.bets = await global.db.engine.find(global.systems.bets.collection.users);
      }
    } catch (e) {
      global.log.error(e.stack);
    } finally {
      this.timeouts.betsInterval = setTimeout(() => this.interval(), 1000);
    }
  }
开发者ID:sogehige,项目名称:SogeBot,代码行数:16,代码来源:bets.ts

示例6: registerBridge

registerBridge("setTimeout", (rt: Runtime, bridge: Bridge, fn: ivm.Reference<() => void>, timeout: number) => {
  const t = setTimeout(() => {
    try {
      fn.applyIgnored(null, [])
    } catch (e) {
      // ignore
    }
    try {
      fn.release()
    } catch (e) {
      // ignore
    }
  }, timeout)
  t.unref()
  return Promise.resolve(new ivm.Reference(t))
})
开发者ID:dianpeng,项目名称:fly,代码行数:16,代码来源:timers.ts

示例7: searchLessons

export function searchLessons(req: Request, res: Response) {

    console.log('Searching for lessons ...');

//    const error = (Math.random() >= 0.5);

//    if (error) {
//        console.log("ERROR loading lessons!");
//        res.status(500).json({message: 'random error occurred.'});
//    }
//    else {


        const queryParams = req.query;

        const courseId = queryParams.courseId,
            filter = queryParams.filter || '',
            sortOrder = queryParams.sortOrder,
            pageNumber = parseInt(queryParams.pageNumber) || 0,
            pageSize = parseInt(queryParams.pageSize);

        let lessons = Object.values(LESSONS).filter(lesson => lesson.courseId == courseId).sort((l1, l2) => l1.id - l2.id);

        if (filter) {
            lessons = lessons.filter(lesson => lesson.description.trim().toLowerCase().search(filter.toLowerCase()) >= 0);
        }

        if (sortOrder == "desc") {
            lessons = lessons.reverse();
        }

        const initialPos = pageNumber * pageSize;

        const lessonsPage = lessons.slice(initialPos, initialPos + pageSize);

        setTimeout(() => {
            res.status(200).json({payload: lessonsPage});
        },1000);

 //   }




}
开发者ID:mrplanktonlex,项目名称:angular-ngrx-course,代码行数:45,代码来源:search-lessons.route.ts

示例8: tryRead

    function tryRead() {
      attempts += 1
      try {
        const chunk = info.stream.read(1024 * 1024)
        log.debug("chunk is null? arraybuffer?", !chunk, chunk instanceof Buffer)

        if (chunk) {
          info.readLength += Buffer.byteLength(chunk)
        }

        if (!chunk && !info.endedAt && attempts < 10) {
          // no chunk, not ended, attemptable
          setTimeout(tryRead, 20 * attempts)
          return
        }

        if (!chunk && attempts >= 10) {
          cb.applyIgnored(null, [null, null])
        } else if (chunk instanceof Buffer) {
          // got a buffer
          cb.applyIgnored(null, [null, transferInto(chunk)])
        }
        // got something else
        else {
          cb.applyIgnored(null, [null, chunk])
        }
        try {
          cb.release()
        } catch (e) {
          // ignore
        }
      } catch (e) {
        cb.applyIgnored(null, [e.message])
        try {
          cb.release()
        } catch (e) {
          // ignore
        }
      }
    }
开发者ID:dianpeng,项目名称:fly,代码行数:40,代码来源:stream_manager.ts

示例9: saveCourse

export function saveCourse(req: Request, res: Response) {

    const id = req.params["id"],
        changes = req.body;

    console.log("Saving course", id, JSON.stringify(changes));


    COURSES[id] = {
        ...COURSES[id],
        ...changes
    };

    setTimeout(() => {

        res.status(200).json(COURSES[id]);

    }, 2000);



}
开发者ID:mrplanktonlex,项目名称:rxjs-course,代码行数:22,代码来源:save-course.route.ts

示例10: testPromisify

{
    {
        const immediateId = timers.setImmediate(() => { console.log("immediate"); });
        timers.clearImmediate(immediateId);
    }
    {
        const counter = 0;
        const timeout = timers.setInterval(() => { console.log("interval"); }, 20);
        timeout.unref();
        timeout.ref();
        timers.clearInterval(timeout);
    }
    {
        const counter = 0;
        const timeout = timers.setTimeout(() => { console.log("timeout"); }, 20);
        timeout.unref();
        timeout.ref();
        timers.clearTimeout(timeout);
    }
    async function testPromisify() {
        const setTimeout = util.promisify(timers.setTimeout);
        let v: void = await setTimeout(100); // tslint:disable-line no-void-expression void-return
        let s: string = await setTimeout(100, "");

        const setImmediate = util.promisify(timers.setImmediate);
        v = await setImmediate(); // tslint:disable-line no-void-expression
        s = await setImmediate("");
    }
}
开发者ID:Lavoaster,项目名称:DefinitelyTyped,代码行数:29,代码来源:node-tests.ts


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