{"action":"created","issue":{"url":"https://api.github.com/repos/jpaulm/jsfbp/issues/2","labels_url":"https://api.github.com/repos/jpaulm/jsfbp/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/jpaulm/jsfbp/issues/2/comments","events_url":"https://api.github.com/repos/jpaulm/jsfbp/issues/2/events","html_url":"https://github.com/jpaulm/jsfbp/issues/2","id":54905223,"number":2,"title":"Reestablishing a fibre in a callback","user":{"login":"jpaulm","id":312871,"avatar_url":"https://avatars.githubusercontent.com/u/312871?v=3","gravatar_id":"","url":"https://api.github.com/users/jpaulm","html_url":"https://github.com/jpaulm","followers_url":"https://api.github.com/users/jpaulm/followers","following_url":"https://api.github.com/users/jpaulm/following{/other_user}","gists_url":"https://api.github.com/users/jpaulm/gists{/gist_id}","starred_url":"https://api.github.com/users/jpaulm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpaulm/subscriptions","organizations_url":"https://api.github.com/users/jpaulm/orgs","repos_url":"https://api.github.com/users/jpaulm/repos","events_url":"https://api.github.com/users/jpaulm/events{/privacy}","received_events_url":"https://api.github.com/users/jpaulm/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jpaulm/jsfbp/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-20T16:32:24Z","updated_at":"2015-01-22T07:48:31Z","closed_at":null,"body":"@bjouhier  Sorry to keep bothering you, but I'm a bit confused about running a callback under a fibre - not even sure if that's the right terminology!\r\n\r\nI had my test case with the asynchronous reader working (I thought), but when I tried a more complex case (fbptest2), I found that the callback wasn't picking up the original fibre.  I now seem to have gotten it working - with some added logic in reader.js, and some more functions in fbp.js, but I just wanted to ask what controls the fibre's lifetime?  I seem to have been able to reconnect to my original fibre from the callback, using Fiber.current = xxx, but I don't know how that works under the covers!  \r\n\r\nHope this makes sense!  I'd like to be a bit more comfortable with what I've done!\r\n\r\nBest regards, and thanks for all your help!\r\n\r\nPaul"},"comment":{"url":"https://api.github.com/repos/jpaulm/jsfbp/issues/comments/70982968","html_url":"https://github.com/jpaulm/jsfbp/issues/2#issuecomment-70982968","issue_url":"https://api.github.com/repos/jpaulm/jsfbp/issues/2","id":70982968,"user":{"login":"bjouhier","id":415044,"avatar_url":"https://avatars.githubusercontent.com/u/415044?v=3","gravatar_id":"","url":"https://api.github.com/users/bjouhier","html_url":"https://github.com/bjouhier","followers_url":"https://api.github.com/users/bjouhier/followers","following_url":"https://api.github.com/users/bjouhier/following{/other_user}","gists_url":"https://api.github.com/users/bjouhier/gists{/gist_id}","starred_url":"https://api.github.com/users/bjouhier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjouhier/subscriptions","organizations_url":"https://api.github.com/users/bjouhier/orgs","repos_url":"https://api.github.com/users/bjouhier/repos","events_url":"https://api.github.com/users/bjouhier/events{/privacy}","received_events_url":"https://api.github.com/users/bjouhier/received_events","type":"User","site_admin":false},"created_at":"2015-01-22T07:48:31Z","updated_at":"2015-01-22T07:48:31Z","body":"Nomally you start your fiber with:\r\n```javascript\r\nFiber(function fiberBody() {\r\n  // your code\r\n}).run();\r\n```\r\nThe lifetime is the fiber is tied to the execution of `fiberBody`. `fiberBody` may yield several times but it will eventually return and at that time there is not much you can do with the fiber.\r\n\r\n`Fiber.current` points to the expected fiber when you are in `fiberBody` or in one of the functions that is called by `fiberBody`. But you should not use it inside an I/O callback because I/O callbacks are called by node's event loop, not by `fiberBody`. If you need it inside a callback you should use a closure (capture `Fiber.current` into a variable in scope which is invoked by `fiberBody`."}}