{ "id": "62739", "key": "TIMOB-2107", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "10100", "description": "This issue won't be actioned.", "name": "Won't Do" }, "resolutiondate": "2020-01-09T18:33:03.000+0000", "created": "2011-04-15T03:10:38.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "core" ], "versions": [ { "id": "13505", "description": "Release 3.0.0", "name": "Release 3.0.0", "archived": true, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [], "assignee": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2020-01-09T18:33:03.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "{html}

When HTTPClients are opened in synchronous mode (the third\r\nparameter set to false), the send call returns before executing the\r\nattached callbacks. I know it seems weird wanting to use callbacks\r\nwith a synchronous call, but this behaviour seems to be expected of\r\nother XHR like objects by libraries like jQuery and SpazCore.

\r\n

Try running this code to reproduce the issue:

\r\n
\r\n  var bool, xhr;\r\n  xhr = Titanium.Network.createHTTPClient();\r\n  bool = false;\r\n  xhr.open(\"GET\", \"http://api.twitter.com/1/help/test.json\", false);\r\n  xhr.onreadystatechange = function() {\r\n    Ti.API.debug(\"Ready State change to \" + xhr.status);\r\n    if (xhr.status === 200) {\r\n      Ti.API.debug(\"Setting bool to true\");\r\n      bool = true;\r\n    }\r\n  };\r\n  xhr.send();\r\n  Ti.API.debug(\"Bool is: \" + bool);\r\n
\r\n

Output I get from iPhone SDK v4.1, Titanium Mobile SDK\r\nv1.4.0

\r\n
\r\n[DEBUG] Bool is: false\r\n[DEBUG] Ready State change to 200\r\n[DEBUG] Setting bool to true\r\n
\r\n

What I think I should see:

\r\n
\r\n[DEBUG] Ready State change to 200\r\n[DEBUG] Setting bool to true\r\n[DEBUG] Bool is: true\r\n
\r\n

If you run this code in chrome in a console on\r\napi.twitter.com:

\r\n
\r\n  var bool, xhr;\r\n  xhr = new XMLHttpRequest();\r\n  bool = false;\r\n  xhr.open(\"GET\", \"http://api.twitter.com/1/help/test.json\", false);\r\n  xhr.onreadystatechange = function() {
\r\n
\r\n\r\n\r\n
\r\n
\r\n
\r\nconsole.log("Ready State change to " + xhr.status);\r\nif (xhr.status === 200) {\r\n  console.log("Setting bool to true");\r\n  bool = true;\r\n}\r\n
\r\n
\r\n\r\n\r\n
\r\n };\r\n xhr.send();\r\n console.log(\"Bool is: \" + bool);\r\n
\r\n

You get the above expected output:

\r\n
\r\nReady State change to 200\r\nSetting bool to true\r\nBool is: true\r\n
\r\n

Can Titanium's XHR implementation be changed to conform?

{html}", "attachment": [], "flagged": false, "summary": "iOS: HTTPClient doesn't execute callbacks before returning in synchronous mode", "creator": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "127510", "author": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Confirmed this issue persists in the mobile SDK v1.4.1.1

{html}", "updateAuthor": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:10:38.000+0000", "updated": "2011-04-15T03:10:38.000+0000" }, { "id": "127511", "author": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Any update on this folks? I'd love to use some of the stuff this\nbreaks!

{html}", "updateAuthor": { "name": "harrybrundage", "key": "harrybrundage", "displayName": "Harry Brundage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:10:38.000+0000", "updated": "2011-04-15T03:10:38.000+0000" }, { "id": "127512", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

XHR spec does say that these are supposed to be synchronous, but\nwe're purposefully ASYNCHRONOUS. At least on the iOS side, we need\na way to force events to fire synchronously, for cases like\nthis.

{html}", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:10:39.000+0000", "updated": "2011-04-15T03:10:39.000+0000" }, { "id": "209665", "author": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Confirmed SDK 2.2.0.014b86f", "updateAuthor": { "name": "stephentramer", "key": "stephentramer", "displayName": "Stephen Tramer", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-07-26T11:51:33.000+0000", "updated": "2012-07-26T11:51:33.000+0000" }, { "id": "453540", "author": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "It has been decided that this issue should be closed as “Won’t do.” This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. Updating, or creating code may not reproduce the issue reported, or be a valid test case.", "updateAuthor": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-01-09T18:33:03.000+0000", "updated": "2020-01-09T18:33:03.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }