简体   繁体   English

Ember.RSVP.Promise with sync

[英]Ember.RSVP.Promise with sync

Is it possible to pass async as false for Ember.RSVP.Promise ? 是否可以将Ember.RSVP.Promise的async传递为false?

var promise = new Ember.RSVP.Promise(function(resolve, reject) {
return $.ajax({
    url: requestUrl,
    type: 'POST',
    dataType: 'JSON', 
    contentType: 'application/json; charset=utf-8',
    data: JSON.stringify(postData)
}).success(resolve).error(reject);

I mean similar to how we can set when using Ember.$.ajax 我的意思类似于使用Ember。$。ajax时的设置方式

var ajaxReq = Ember.$.ajax({
    url: "/someService",
    data: data,
    type: 'post',
    dataType: 'json',
    async: false,
    contentType: 'application/json'
});

No! 没有! A Promise can not be executed in sync! 一个Promise不能同步执行! This is a javascript limitation. 这是一个JavaScript限制。

And you replay don't want this because you have just one Thread. 而且您不希望重播,因为您只有一个线程。 So blocking that Thread would block everything! 因此,阻止该线程将阻止所有内容!

A Promise is also not only about AJAX! 一个承诺不仅关乎AJAX!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM