That will work ,but since it's a "busy loop", better to use a sleep instead.
eg:
java.lang.Thread.sleep(1000);
This works because you can write java inside Jaggery.

On Wed, Apr 27, 2016 at 12:19 PM, Nalin Sugathapala <nal...@wso2.com> wrote:

> Hi Manu,
>
> I actually want it to run synchronously. The return will be used to
> dynamically generate html. I am executing a WSRequest and I get the feeling
> that I am getting throttled resulting in the WSRequest throwing an error.
>
> Found the following code snippet at [1] to give a time gap between the
> WSRequest calls and stop them getting throttled.
>
> function pause(milliseconds) {
>   var dt = new Date();
>   while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
> }
>
>
> I can use the pause method instead of setTimeout. WDYT?
>
> [1] The 2nd answer in
> http://stackoverflow.com/questions/4122268/using-settimeout-synchronously-in-javascript
>
> Cheers,
> Nalin
>
>
> On Wed, Apr 27, 2016 at 7:29 PM, Manuranga Perera <m...@wso2.com> wrote:
>
>> Since setTimeout is running in a different thread, above code might not
>> work. (didn't have time to test).
>> But you can do something like
>>
>> function fetchContact(token,retryCount){ retryCount = (typeof retryCount
>> === 'undefined') ? 5 : retryCount; try{ //actual logic
>> //note that using return form here is not a good idea
>> //because we might be in a different thread }catch (e){ if(retryCount >
>> 0){ setTimeout(function() {a(token,retryCount-1)},1000); } } }
>>
>> fetchContact(3243); // will try it for at max 5 times
>>
>> BTW, better to move the thread to dev list.
>>
>> On Wed, Apr 27, 2016 at 4:30 AM, Nalin Sugathapala <nal...@wso2.com>
>> wrote:
>>
>>> So did an ugly hack by yours truly and an elegant fix as proposed by
>>> Tanya. I can think of two possible reasons for the error:
>>>   a) There is a time out issue, which is fixed by using the
>>> CONNECTION_TIMEOUT property that is sent into the open method
>>>
>>> options.CONNECTION_TIMEOUT = 120000;
>>> salesforce.open(options, salesforce_url, false);
>>>
>>>   b) a possible throttling issue at Salesforce, which is the ugly hack
>>> ;). I retry 5 times and give up.
>>>
>>> // variable introduced to allow 5 retries for the before giving up
>>> var retry = 0;
>>>
>>> function fetchContact(token) {
>>>
>>>    try {
>>>       <the code for the function>
>>>
>>>       retry = 0;
>>>       return certs;
>>>
>>>    } catch (e) {
>>>        if (retry <5)
>>>        {
>>>            retry += 1;
>>>            return setTimeout(fetchContact(token), 1000);
>>>        } else {
>>>            retry = 0;
>>>           return {error: e};
>>>       }
>>>    }
>>>
>>> }
>>>
>>> Can you think of a better way of doing this.
>>>
>>> Found [1] that talks about a possible time out.
>>>
>>> [1]
>>> http://salesforce.stackexchange.com/questions/13187/connection-refused-error-message-coming-from-a-java-client-connecting-to-salesfo
>>>
>>> Cheers,
>>> Nalin
>>>
>>> On Wed, Apr 27, 2016 at 1:30 AM, Jonathan Marsh <jonat...@wso2.com>
>>> wrote:
>>>
>>>> I got a similar error quite often when running the sales dashboard
>>>> tools – a refresh would successfully log in.  I never got that on a local
>>>> machine and when I migrated to WSO2 App Cloud it never occurs.  Perhaps
>>>> it’s a network timeout or something?
>>>>
>>>>
>>>>
>>>> *From:* Nalin Sugathapala [mailto:nal...@wso2.com]
>>>> *Sent:* Tuesday, April 26, 2016 2:20 AM
>>>> *To:* Jonathan Marsh; Manuranga Perera; Dulitha Wijewantha
>>>> *Subject:* Strange error that I encounter
>>>>
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> I keep encountering an error :[2016-04-26 14:32:27,487]  INFO
>>>> {org.apache.axis2.transport.http.HTTPSender} -  Unable to sendViaPost to
>>>> url[https://login.salesforce.com/services/Soap/c/23.0/XXXXXXXXXXXXX;]
>>>>
>>>> The XXXXXXXXXXXXX is my id.
>>>>
>>>> This is something that comes on and off. Hard to replicate. But don't
>>>> want it poping up in production.
>>>>
>>>> Do you have any idea why this is?
>>>>
>>>> Cheers,
>>>>
>>>> Nalin
>>>>
>>>>
>>>> --
>>>>
>>>> Nalin Sugathapala
>>>>
>>>> *Training Program ManagerWSO2, Inc.*
>>>>
>>>> Mobile : +94 (0) 777 560 525
>>>> <%2B94%20%280%29%20773%20451194>
>>>>
>>>> Tel      : +94 112 145 345
>>>>
>>>> nal...@wso2.com <thili...@wso2.com>
>>>>
>>>
>>>
>>>
>>> --
>>> Nalin Sugathapala
>>>
>>> *Training Program ManagerWSO2, Inc.*
>>> Mobile : +94 (0) 777 560 525
>>> <%2B94%20%280%29%20773%20451194>
>>> Tel      : +94 112 145 345
>>> nal...@wso2.com <thili...@wso2.com>
>>>
>>
>>
>>
>> --
>> With regards,
>> *Manu*ranga Perera.
>>
>> phone : 071 7 70 20 50
>> mail : m...@wso2.com
>>
>
>
>
> --
> Nalin Sugathapala
>
> *Training Program ManagerWSO2, Inc.*
> Mobile : +94 (0) 777 560 525
> <%2B94%20%280%29%20773%20451194>
> Tel      : +94 112 145 345
> nal...@wso2.com <thili...@wso2.com>
>



-- 
With regards,
*Manu*ranga Perera.

phone : 071 7 70 20 50
mail : m...@wso2.com
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to