{"action":"created","issue":{"url":"https://api.github.com/repos/skulpt/skulpt/issues/345","labels_url":"https://api.github.com/repos/skulpt/skulpt/issues/345/labels{/name}","comments_url":"https://api.github.com/repos/skulpt/skulpt/issues/345/comments","events_url":"https://api.github.com/repos/skulpt/skulpt/issues/345/events","html_url":"https://github.com/skulpt/skulpt/pull/345","id":58857821,"number":345,"title":"first try at adding suspensions to updatePixel","user":{"login":"bnmnetp","id":51115,"avatar_url":"https://avatars.githubusercontent.com/u/51115?v=3","gravatar_id":"","url":"https://api.github.com/users/bnmnetp","html_url":"https://github.com/bnmnetp","followers_url":"https://api.github.com/users/bnmnetp/followers","following_url":"https://api.github.com/users/bnmnetp/following{/other_user}","gists_url":"https://api.github.com/users/bnmnetp/gists{/gist_id}","starred_url":"https://api.github.com/users/bnmnetp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnmnetp/subscriptions","organizations_url":"https://api.github.com/users/bnmnetp/orgs","repos_url":"https://api.github.com/users/bnmnetp/repos","events_url":"https://api.github.com/users/bnmnetp/events{/privacy}","received_events_url":"https://api.github.com/users/bnmnetp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-02-25T06:40:57Z","updated_at":"2015-02-27T07:28:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/skulpt/skulpt/pulls/345","html_url":"https://github.com/skulpt/skulpt/pull/345","diff_url":"https://github.com/skulpt/skulpt/pull/345.diff","patch_url":"https://github.com/skulpt/skulpt/pull/345.patch"},"body":"In an attempt to really get my head around suspensions, I thought I would try to add suspensions to the image module.  I have a couple of goals in mind:\r\n\r\n1.  I would like to be able to use updatePixel in a way that when a single pixel is changed, that change would be reflected in the image in the browser window, this would give sutdents a much better visual understanding of nested iteration patterns.\r\n\r\n2.  I would like to be able to grab an image from an arbitrary URL and bring it in for working on.  Right now the module is limited to working with images that are already working on the page.  I figure once I have this fully understood and working this knowledge can be used to overhaul our file handling in the main body of skulpt.\r\n\r\nMy first naive attempt to add suspensions to the updatePixel function looks like the following.\r\n\r\n```javascript\r\n\t    $loc.updatePixel = new Sk.builtin.func(function (self, pixel){\r\n            var susp = new Sk.misceval.Suspension();\r\n            susp.resume = function() { return Sk.builtin.none.none$; }\r\n            susp.data = {\r\n                type: \"Sk.promise\",\r\n                promise: new Promise(function(resolve) {\r\n                    var x = Sk.builtin.asnum$(Sk.misceval.callsim(pixel.getX, pixel));\r\n                    var y = Sk.builtin.asnum$(Sk.misceval.callsim(pixel.getY, pixel));\r\n                    var index = (y * 4) * self.width + (x * 4);\r\n                    self.imagedata.data[index] = Sk.builtin.asnum$(Sk.misceval.callsim(pixel.getRed, pixel));\r\n                    self.imagedata.data[index + 1] = Sk.builtin.asnum$(Sk.misceval.callsim(pixel.getGreen, pixel));\r\n                    self.imagedata.data[index + 2] = Sk.builtin.asnum$(Sk.misceval.callsim(pixel.getBlue, pixel));\r\n                    self.imagedata.data[index + 3] = 255;\r\n                    resolve();\r\n                })};\r\n            return susp;\r\n\t    });\r\n```\r\nI took this basically by following the example in time.  But turtle and others do things much differently.  In particular the chaining that @meredydd just added seems like it might be relevant here.  So, I'm looking for comments and discussion to make sure I get this right, and to make sure I understand what I'm doing so I can better follow other Suspension related PR's.\r\n\r\nBrad"},"comment":{"url":"https://api.github.com/repos/skulpt/skulpt/issues/comments/76350295","html_url":"https://github.com/skulpt/skulpt/pull/345#issuecomment-76350295","issue_url":"https://api.github.com/repos/skulpt/skulpt/issues/345","id":76350295,"user":{"login":"LeszekSwirski","id":593597,"avatar_url":"https://avatars.githubusercontent.com/u/593597?v=3","gravatar_id":"","url":"https://api.github.com/users/LeszekSwirski","html_url":"https://github.com/LeszekSwirski","followers_url":"https://api.github.com/users/LeszekSwirski/followers","following_url":"https://api.github.com/users/LeszekSwirski/following{/other_user}","gists_url":"https://api.github.com/users/LeszekSwirski/gists{/gist_id}","starred_url":"https://api.github.com/users/LeszekSwirski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeszekSwirski/subscriptions","organizations_url":"https://api.github.com/users/LeszekSwirski/orgs","repos_url":"https://api.github.com/users/LeszekSwirski/repos","events_url":"https://api.github.com/users/LeszekSwirski/events{/privacy}","received_events_url":"https://api.github.com/users/LeszekSwirski/received_events","type":"User","site_admin":false},"created_at":"2015-02-27T07:28:23Z","updated_at":"2015-02-27T07:28:23Z","body":"As I recall, there's some complication with Suspensions inheriting their children's data, and this the reason for the awkward data check. I don't entirely remember though, I'd have to refresh my memory to explain this in more detail. "}}