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


TypeScript LinkedList.addLast方法代碼示例

本文整理匯總了TypeScript中@phosphor/collections.LinkedList.addLast方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LinkedList.addLast方法的具體用法?TypeScript LinkedList.addLast怎麽用?TypeScript LinkedList.addLast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@phosphor/collections.LinkedList的用法示例。


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

示例1: runMessageLoop

  /**
   * Run an iteration of the message loop.
   *
   * This will process all pending messages in the queue. If a message
   * is added to the queue while the message loop is running, it will
   * be processed on the next cycle of the loop.
   */
  function runMessageLoop(): void {
    // Clear the task ID so the next loop can be scheduled.
    loopTaskID = 0;

    // If the message queue is empty, there is nothing else to do.
    if (messageQueue.isEmpty) {
      return;
    }

    // Add a sentinel value to the end of the queue. The queue will
    // only be processed up to the sentinel. Messages posted during
    // this cycle will execute on the next cycle.
    let sentinel: PostedMessage = { handler: null, msg: null };
    messageQueue.addLast(sentinel);

    // Enter the message loop.
    while (true) {
      // Remove the first posted message in the queue.
      let posted = messageQueue.removeFirst()!;

      // If the value is the sentinel, exit the loop.
      if (posted === sentinel) {
        return;
      }

      // Dispatch the message if it has not been cleared.
      if (posted.handler && posted.msg) {
        sendMessage(posted.handler, posted.msg);
      }
    }
  }
開發者ID:rlugojr,項目名稱:phosphor,代碼行數:38,代碼來源:index.ts

示例2: it

      it('should add a value to the end of the list', () => {
        let list = new LinkedList<number>();

        expect(list.isEmpty).to.equal(true);
        expect(list.length).to.equal(0);
        expect(list.first).to.equal(undefined);
        expect(list.last).to.equal(undefined);

        let n1 = list.addLast(99);

        expect(list.isEmpty).to.equal(false);
        expect(list.length).to.equal(1);
        expect(list.first).to.equal(99);
        expect(list.last).to.equal(99);

        let n2 = list.addLast(42);

        expect(list.isEmpty).to.equal(false);
        expect(list.length).to.equal(2);
        expect(list.first).to.equal(99);
        expect(list.last).to.equal(42);

        let n3 = list.addLast(7);

        expect(list.isEmpty).to.equal(false);
        expect(list.length).to.equal(3);
        expect(list.first).to.equal(99);
        expect(list.last).to.equal(7);

        expect(toArray(list)).to.deep.equal([99, 42, 7]);

        expect(n1.list).to.equal(list);
        expect(n1.next).to.equal(n2);
        expect(n1.prev).to.equal(null);
        expect(n1.value).to.equal(99);

        expect(n2.list).to.equal(list);
        expect(n2.next).to.equal(n3);
        expect(n2.prev).to.equal(n1);
        expect(n2.value).to.equal(42);

        expect(n3.list).to.equal(list);
        expect(n3.next).to.equal(null);
        expect(n3.prev).to.equal(n2);
        expect(n3.value).to.equal(7);
      });
開發者ID:afshin,項目名稱:phosphor,代碼行數:46,代碼來源:linkedlist.spec.ts

示例3: enqueueMessage

  /**
   * Add a message to the end of the message queue.
   *
   * This will automatically schedule a run of the message loop.
   */
  function enqueueMessage(handler: IMessageHandler, msg: Message): void {
    // Add the posted message to the queue.
    messageQueue.addLast({ handler, msg });

    // Bail if a loop task is already pending.
    if (loopTaskID !== 0) {
      return;
    }

    // Schedule a run of the message loop.
    loopTaskID = schedule(runMessageLoop);
  }
開發者ID:rlugojr,項目名稱:phosphor,代碼行數:17,代碼來源:index.ts


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