当前位置: 首页>>代码示例>>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;未经允许,请勿转载。