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


TypeScript es6-promise.Promise類代碼示例

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


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

示例1: it

  it('should convert a resolved promise to a stream', (done: any) => {
    const stream = xs.from(Promise.resolve('yes'));
    let nextSent = false;

    stream.addListener({
      next: (x: string) => {
        assert.strictEqual(x, 'yes');
        nextSent = true;
      },
      error: (err: any) => done(err),
      complete: () => {
        assert.strictEqual(nextSent, true);
        done();
      },
    });
  });
開發者ID:staltz,項目名稱:xstream,代碼行數:16,代碼來源:from.ts

示例2: dispatch

 .then((result) => {
     dispatch({
         type: GET,
         data: result.data,
         name: {
             lastName: _.get(result.data, 'name.last', ''),
             firstName: _.get(result.data, 'name.first', ''),
             middleName: _.get(result.data, 'name.middle', '')
         }
     })
     return Promise.resolve({ 
         lastName: _.get(result.data, 'name.last', ''),
         firstName: _.get(result.data, 'name.first', ''),
         middleName: _.get(result.data, 'name.middle', '')
     });
 })
開發者ID:Emunoz88,項目名稱:node-hapi-react-redux-sass-typescript-mongo-webpack-hmr-gulp,代碼行數:16,代碼來源:actions.ts

示例3: String

 return new Promise<School>((resolve, reject) => {
     let ans: School = obj;
     Promise.all([
             course_list({school_id: String(obj.school_id)}),
             person_school_list({school_id: String(obj.school_id)}),
             person_comment_list({school_id: String(obj.school_id)}),
          ]
     ).then((values) => {
         ans.course_list = values[0];
         ans.person_school_list = values[1];
         ans.person_comment_list = values[2];
         resolve(ans);
     }).catch((error) => {
         reject(error);
     })
 })
開發者ID:lesh-dev,項目名稱:core,代碼行數:16,代碼來源:api_connect.ts

示例4: it

 it("should sort JSON files as text if one or more aren't JSON", function() {
   let now = new Date();
   let future = new Date(2100, 12, 1);
   let files = [
     new FileContents('test1.js', new Date(), '', JSON.stringify({ created: now })),
     new FileContents('test2.js', new Date(), '', 'not JSON')
   ];
   return Promise.resolve()
     .then(() => {
       return subject(files);
     })
     .then((result) => {
       assert.isNotNull(result);
       assert.equal(result.format, Format.Text);
       assert.equal(result.contents, ['not JSON', JSON.stringify({ created: now })].join('\n'));
     });
 });
開發者ID:colinmathews,項目名稱:s3-append,代碼行數:17,代碼來源:sort-spec.ts

示例5: context

 context('when map data is NOT present', function () {
   let hiddenMapPromise: Promise<Client.JQueryDetailSelectors>;
   before(function () {
     const detailsWithoutMap = _.extend({}, TEST_DETAILS, { map: null });
     hiddenMapPromise = createPostUpdatePromise(detailsWithoutMap);
   });
   after(function (done) {
     revertToOriginalTestDetails(done);
   });
   it('should hide the map', function () {
     return hiddenMapPromise.then($selectors => {
       expect(elemIsHidden($selectors.$playerMap));
       expect(normalize($selectors.$playerMap.text())).to.equal('');
       return $selectors;
     });
   });
 });
開發者ID:zthomae,項目名稱:xanadu,代碼行數:17,代碼來源:clientSpec.ts

示例6: Promise

 return new Promise((res, rej) => {
   isAuth.then(a => {
     if (a) {
       db.run(
         "DELETE FROM entries WHERE id = ?",
         [entryId],
         (err) => {
           if (err) {
             errors.push(err);
             rej(errors);
           } else {
             res();
           }
         });
     }
   });
 });
開發者ID:Ethan826,項目名稱:diet-tracker,代碼行數:17,代碼來源:db.ts

示例7: findUserIps

    /**
     * Attempts to find ip addresses of the user, withing the specified
     * timeout.
     *
     * @param timeout
     * @returns {Promise<IPAddress[]>} Returns a promise resolved with an
     * array of ip addresses of the user on success.
     */
    public static findUserIps(timeout:number = 1000):Promise<IPAddress[]> {
        let RTCPeerConnection = window['RTCPeerConnection']
            || window['mozRTCPeerConnection']
            || window['webkitRTCPeerConnection'];
        let rtcConfig = {
            iceServers: [{urls: "stun:stun.services.mozilla.com"}]
        };

        if (!RTCPeerConnection) {
            return Promise.reject('RTCPeerConnection not supported.');
        }

        return new Promise((resolve, reject) => {
            let timeoutId;
            let ipAddresses:IPAddress[] = [];
            let peerConnection = new RTCPeerConnection(rtcConfig);
            let onIceCandidate = (evt) => {
                if (evt.candidate) {
                    let iceCandidate = evt.candidate;
                    let ip = WebRTCIPFinder.parseIpFromIceCandidate(iceCandidate);
                    if (ip != null && ipAddresses.every(other => !ip.equals(other))) {
                        ipAddresses.push(ip);
                    }
                }
            };
            let done = (error?) => {
                clearTimeout(timeoutId);
                peerConnection.onicecandidate = null;
                peerConnection.close();
                peerConnection = null;
                if (error) {
                    reject(error);
                } else {
                    resolve(ipAddresses);
                }
            };

            peerConnection.onicecandidate = onIceCandidate;
            peerConnection.createDataChannel('');
            peerConnection.createOffer((sdp) => {
                peerConnection.setLocalDescription(sdp);
            }, (err) => done(err));
            timeoutId = setTimeout(done, timeout);
        });
    }
開發者ID:verath,項目名稱:router-hijack,代碼行數:53,代碼來源:WebRTCIPFinder.ts


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