{"action":"created","issue":{"url":"https://api.github.com/repos/folktale/data.task/issues/35","repository_url":"https://api.github.com/repos/folktale/data.task","labels_url":"https://api.github.com/repos/folktale/data.task/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/folktale/data.task/issues/35/comments","events_url":"https://api.github.com/repos/folktale/data.task/issues/35/events","html_url":"https://github.com/folktale/data.task/issues/35","id":155709339,"number":35,"title":"Any example usage of `cleanup`?","user":{"login":"safareli","id":1932383,"avatar_url":"https://avatars.githubusercontent.com/u/1932383?v=3","gravatar_id":"","url":"https://api.github.com/users/safareli","html_url":"https://github.com/safareli","followers_url":"https://api.github.com/users/safareli/followers","following_url":"https://api.github.com/users/safareli/following{/other_user}","gists_url":"https://api.github.com/users/safareli/gists{/gist_id}","starred_url":"https://api.github.com/users/safareli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safareli/subscriptions","organizations_url":"https://api.github.com/users/safareli/orgs","repos_url":"https://api.github.com/users/safareli/repos","events_url":"https://api.github.com/users/safareli/events{/privacy}","received_events_url":"https://api.github.com/users/safareli/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-05-19T10:58:07Z","updated_at":"2016-05-20T16:56:08Z","closed_at":null,"body":"It will be nice to provide some example of using `cleanup`. I can't understand why do we need it?"},"comment":{"url":"https://api.github.com/repos/folktale/data.task/issues/comments/220660291","html_url":"https://github.com/folktale/data.task/issues/35#issuecomment-220660291","issue_url":"https://api.github.com/repos/folktale/data.task/issues/35","id":220660291,"user":{"login":"robotlolita","id":406477,"avatar_url":"https://avatars.githubusercontent.com/u/406477?v=3","gravatar_id":"","url":"https://api.github.com/users/robotlolita","html_url":"https://github.com/robotlolita","followers_url":"https://api.github.com/users/robotlolita/followers","following_url":"https://api.github.com/users/robotlolita/following{/other_user}","gists_url":"https://api.github.com/users/robotlolita/gists{/gist_id}","starred_url":"https://api.github.com/users/robotlolita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robotlolita/subscriptions","organizations_url":"https://api.github.com/users/robotlolita/orgs","repos_url":"https://api.github.com/users/robotlolita/repos","events_url":"https://api.github.com/users/robotlolita/events{/privacy}","received_events_url":"https://api.github.com/users/robotlolita/received_events","type":"User","site_admin":false},"created_at":"2016-05-20T16:56:08Z","updated_at":"2016-05-20T16:56:08Z","body":"Creating and transforming Tasks stays the same:\r\n\r\n```js\r\nconst Task = require('folktale').data.task;\r\n\r\nfunction delay(time) {\r\n  return new Task((reject, resolve) => {\r\n    return setTimeout(_ => resolve(), time)\r\n  }, clearTimeout);\r\n}\r\n\r\nconst helloIn10 = delay(10).map(v => \"Hello!\");\r\n```\r\n\r\nBut instead of `.fork()` for running the tasks, you have a `.run()` method. The `.run()` method returns a `TaskExecution` object, which lets you cancel the task, or get the value of the task:\r\n\r\n```js\r\nconst execution = helloIn10.run();\r\n\r\n// Cancelling a particular execution of a Task:\r\nexecution.cancel();\r\n\r\n// Getting the value of executing a Task:\r\n// (Future is a Monad, like Task, but it doesn't run any computation, \r\n// it just eventually provides a value)\r\nexecution.future().cata({\r\n  Cancelled: _ => ...,\r\n  Resolved: _ => ...,\r\n  Rejected: _ => ...\r\n});\r\n\r\n// You can also use a promise, which lets you use async/await:\r\nconst value = await execution.promise();\r\n```\r\n\r\nTaskExecution objects take care of memoisation, providing futures, cancelling tasks, and collecting resources when the task finishes running or is cancelled, so this should make it easier for people to use Task."}}
{"actor":{"display_login":"robotlolita"}}