{"action":"created","comment":{"url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/comments/40405279","id":40405279,"diff_hunk":"@@ -1,111 +1,203 @@\n use ooc-collections\n+use ooc-base\n \n import structs/LinkedList\n import threading/Thread\n+import threading/native/ConditionUnix\n+import os/Time\n \n-ThreadJob: class {\n-\t_body: Func\n-\tinit: func (=_body)\n-\t_execute: func { this _body() }\n-\trun: virtual func {\n-\t\tthis _execute()\n-\t\tthis free()\n-\t}\n+_TaskState: enum {\n+\tUnfinished\n+\tFinished\n+\tCancelled\n }\n \n-SynchronizedThreadJob: class extends ThreadJob {\n-\t_finishedCondition := WaitCondition new()\n-\t_mutex := Mutex new()\n-\t_finished := false\n-\tfinished ::= this _finished\n-\t_freeOnCompletion := false\n-\tinit: func (body: Func) { super(body) }\n+_Task: class {\n+\t_mutex: Mutex\n+\t_action: Func\n+\t_state : _TaskState\n+\t_freeDirectly: Bool\n+\tinit: func (=_action, =_mutex) {\n+\t\t_state = _TaskState Unfinished\n+\t\t_mutex = Mutex new()\n+\t}\n \tfree: override func {\n-\t\tthis _mutex lock()\n-\t\tif (!this _finished) {\n-\t\t\tthis _freeOnCompletion = true\n-\t\t\tthis _mutex unlock()\n-\t\t} else {\n-\t\t\tthis _mutex unlock()\n-\t\t\tthis _mutex destroy()\n-\t\t\tthis _finishedCondition free()\n+\t\tif (this _state != _TaskState Unfinished)\n+\t\t\tthis _freeDirectly = true\n+\t\telse\n \t\t\tsuper()\n-\t\t}\n \t}\n-\trun: override func {\n-\t\tthis _execute()\n-\t\tthis _mutex lock()\n-\t\tthis _finished = true\n-\t\tif (this _freeOnCompletion) {\n-\t\t\tthis _mutex unlock()\n+\trun: virtual func (=_mutex) {\n+\t\tthis _action()\n+\t\t_mutex lock()\n+\t\tif (this _state != _TaskState Cancelled)\n+\t\t\tthis _state = _TaskState Finished\n+\t\t_mutex unlock()\n+\t\tif (this _freeDirectly)\n \t\t\tthis free()\n-\t\t} else {\n-\t\t\tthis _mutex unlock()\n-\t\t\tthis _finishedCondition broadcast()\n-\t\t}\n \t}\n-\twait: func {\n+}\n+\n+_ResultTask: class <T> extends _Task {\n+\t_result: Cell<T>\n+\t_resultAction: Func -> T\n+\tinit: func (=_resultAction, =_mutex) {\n+\t\tthis _state = _TaskState Unfinished\n+\t}\n+\tfree: func {\n+\t\tif (this _state != _TaskState Unfinished)\n+\t\t\tthis _freeDirectly = true\n+\t\telse\n+\t\t\tsuper()\n+\t}\n+\trun: override func (=_mutex) {\n+\t\ttemporary := Cell<T> new(this _resultAction())\n \t\tthis _mutex lock()\n-\t\tif (!this _finished)\n-\t\t\tthis _finishedCondition wait(this _mutex)\n+\t\tthis _result = temporary\n+\t\tif (this _state != _TaskState Cancelled)\n+\t\t\tthis _state = _TaskState Finished\n+\t\tif (this _freeDirectly)\n+\t\t\tthis free()\n \t\tthis _mutex unlock()\n \t}\n }\n \n+_TaskPromise: class extends Promise {\n+\t_task: _Task\n+\tinit: func (=_task)\n+\tfree: override func {\n+\t\tthis _task free()\n+\t\tsuper()\n+\t}\n+\twait: override func -> Bool {\n+\t\tstatus := false\n+\t\twhile (true) {\n+\t\t\tthis _task _mutex lock()\n+\t\t\tif (this _task _state != _TaskState Unfinished) {\n+\t\t\t\tstatus = (this _task _state == _TaskState Finished)\n+\t\t\t\tthis _task _mutex unlock()\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tthis _task _mutex unlock()\n+\t\t\tTime sleepMilli(10)\n+\t\t}\n+\t\tstatus\n+\t}\n+\tcancel: override func -> Bool {","path":"source/base/ThreadPool.ooc","position":123,"original_position":123,"commit_id":"f6825ce23e46ed28cb21a127bfb0711def058b28","original_commit_id":"f6825ce23e46ed28cb21a127bfb0711def058b28","user":{"login":"marcusnaslund","id":14308896,"avatar_url":"https://avatars.githubusercontent.com/u/14308896?v=3","gravatar_id":"","url":"https://api.github.com/users/marcusnaslund","html_url":"https://github.com/marcusnaslund","followers_url":"https://api.github.com/users/marcusnaslund/followers","following_url":"https://api.github.com/users/marcusnaslund/following{/other_user}","gists_url":"https://api.github.com/users/marcusnaslund/gists{/gist_id}","starred_url":"https://api.github.com/users/marcusnaslund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcusnaslund/subscriptions","organizations_url":"https://api.github.com/users/marcusnaslund/orgs","repos_url":"https://api.github.com/users/marcusnaslund/repos","events_url":"https://api.github.com/users/marcusnaslund/events{/privacy}","received_events_url":"https://api.github.com/users/marcusnaslund/received_events","type":"User","site_admin":false},"body":"For now, it allows wait() to return directly (although the task will still run).","created_at":"2015-09-25T07:27:14Z","updated_at":"2015-09-25T07:27:14Z","html_url":"https://github.com/cogneco/ooc-kean/pull/423#discussion_r40405279","pull_request_url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423","_links":{"self":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/comments/40405279"},"html":{"href":"https://github.com/cogneco/ooc-kean/pull/423#discussion_r40405279"},"pull_request":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423"}}},"pull_request":{"url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423","id":45769199,"html_url":"https://github.com/cogneco/ooc-kean/pull/423","diff_url":"https://github.com/cogneco/ooc-kean/pull/423.diff","patch_url":"https://github.com/cogneco/ooc-kean/pull/423.patch","issue_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/423","number":423,"state":"closed","locked":false,"title":"Integration of Promises with Threadpool","user":{"login":"marcusnaslund","id":14308896,"avatar_url":"https://avatars.githubusercontent.com/u/14308896?v=3","gravatar_id":"","url":"https://api.github.com/users/marcusnaslund","html_url":"https://github.com/marcusnaslund","followers_url":"https://api.github.com/users/marcusnaslund/followers","following_url":"https://api.github.com/users/marcusnaslund/following{/other_user}","gists_url":"https://api.github.com/users/marcusnaslund/gists{/gist_id}","starred_url":"https://api.github.com/users/marcusnaslund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcusnaslund/subscriptions","organizations_url":"https://api.github.com/users/marcusnaslund/orgs","repos_url":"https://api.github.com/users/marcusnaslund/repos","events_url":"https://api.github.com/users/marcusnaslund/events{/privacy}","received_events_url":"https://api.github.com/users/marcusnaslund/received_events","type":"User","site_admin":false},"body":"Big changes, but ThreadPool add(...) behaves as before - nothing in vidproc has any objections.","created_at":"2015-09-23T11:41:06Z","updated_at":"2015-09-25T07:27:14Z","closed_at":"2015-09-23T13:02:59Z","merged_at":"2015-09-23T13:02:59Z","merge_commit_sha":"340ad4b90dbb99e74785d1a194ad0a4887e22e8d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423/commits","review_comments_url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423/comments","review_comment_url":"https://api.github.com/repos/cogneco/ooc-kean/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/423/comments","statuses_url":"https://api.github.com/repos/cogneco/ooc-kean/statuses/f6825ce23e46ed28cb21a127bfb0711def058b28","head":{"label":"marcusnaslund:threadpool-promises","ref":"threadpool-promises","sha":"f6825ce23e46ed28cb21a127bfb0711def058b28","user":{"login":"marcusnaslund","id":14308896,"avatar_url":"https://avatars.githubusercontent.com/u/14308896?v=3","gravatar_id":"","url":"https://api.github.com/users/marcusnaslund","html_url":"https://github.com/marcusnaslund","followers_url":"https://api.github.com/users/marcusnaslund/followers","following_url":"https://api.github.com/users/marcusnaslund/following{/other_user}","gists_url":"https://api.github.com/users/marcusnaslund/gists{/gist_id}","starred_url":"https://api.github.com/users/marcusnaslund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcusnaslund/subscriptions","organizations_url":"https://api.github.com/users/marcusnaslund/orgs","repos_url":"https://api.github.com/users/marcusnaslund/repos","events_url":"https://api.github.com/users/marcusnaslund/events{/privacy}","received_events_url":"https://api.github.com/users/marcusnaslund/received_events","type":"User","site_admin":false},"repo":{"id":42990201,"name":"ooc-kean","full_name":"marcusnaslund/ooc-kean","owner":{"login":"marcusnaslund","id":14308896,"avatar_url":"https://avatars.githubusercontent.com/u/14308896?v=3","gravatar_id":"","url":"https://api.github.com/users/marcusnaslund","html_url":"https://github.com/marcusnaslund","followers_url":"https://api.github.com/users/marcusnaslund/followers","following_url":"https://api.github.com/users/marcusnaslund/following{/other_user}","gists_url":"https://api.github.com/users/marcusnaslund/gists{/gist_id}","starred_url":"https://api.github.com/users/marcusnaslund/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcusnaslund/subscriptions","organizations_url":"https://api.github.com/users/marcusnaslund/orgs","repos_url":"https://api.github.com/users/marcusnaslund/repos","events_url":"https://api.github.com/users/marcusnaslund/events{/privacy}","received_events_url":"https://api.github.com/users/marcusnaslund/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/marcusnaslund/ooc-kean","description":"ooc port of parts of Kean.","fork":true,"url":"https://api.github.com/repos/marcusnaslund/ooc-kean","forks_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/forks","keys_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/teams","hooks_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/hooks","issue_events_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/issues/events{/number}","events_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/events","assignees_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/assignees{/user}","branches_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/branches{/branch}","tags_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/tags","blobs_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/git/refs{/sha}","trees_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/statuses/{sha}","languages_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/languages","stargazers_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/stargazers","contributors_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/contributors","subscribers_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/subscribers","subscription_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/subscription","commits_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/commits{/sha}","git_commits_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/git/commits{/sha}","comments_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/comments{/number}","issue_comment_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/issues/comments{/number}","contents_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/contents/{+path}","compare_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/merges","archive_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/downloads","issues_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/issues{/number}","pulls_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/pulls{/number}","milestones_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/milestones{/number}","notifications_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/labels{/name}","releases_url":"https://api.github.com/repos/marcusnaslund/ooc-kean/releases{/id}","created_at":"2015-09-23T09:03:37Z","updated_at":"2015-09-23T09:03:39Z","pushed_at":"2015-09-24T14:10:54Z","git_url":"git://github.com/marcusnaslund/ooc-kean.git","ssh_url":"git@github.com:marcusnaslund/ooc-kean.git","clone_url":"https://github.com/marcusnaslund/ooc-kean.git","svn_url":"https://github.com/marcusnaslund/ooc-kean","homepage":"","size":12098,"stargazers_count":0,"watchers_count":0,"language":"ooc","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cogneco:master","ref":"master","sha":"1b22c64232ed7e76eb59c8ddb68ab2457e22a4d3","user":{"login":"cogneco","id":3601419,"avatar_url":"https://avatars.githubusercontent.com/u/3601419?v=3","gravatar_id":"","url":"https://api.github.com/users/cogneco","html_url":"https://github.com/cogneco","followers_url":"https://api.github.com/users/cogneco/followers","following_url":"https://api.github.com/users/cogneco/following{/other_user}","gists_url":"https://api.github.com/users/cogneco/gists{/gist_id}","starred_url":"https://api.github.com/users/cogneco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cogneco/subscriptions","organizations_url":"https://api.github.com/users/cogneco/orgs","repos_url":"https://api.github.com/users/cogneco/repos","events_url":"https://api.github.com/users/cogneco/events{/privacy}","received_events_url":"https://api.github.com/users/cogneco/received_events","type":"Organization","site_admin":false},"repo":{"id":25256330,"name":"ooc-kean","full_name":"cogneco/ooc-kean","owner":{"login":"cogneco","id":3601419,"avatar_url":"https://avatars.githubusercontent.com/u/3601419?v=3","gravatar_id":"","url":"https://api.github.com/users/cogneco","html_url":"https://github.com/cogneco","followers_url":"https://api.github.com/users/cogneco/followers","following_url":"https://api.github.com/users/cogneco/following{/other_user}","gists_url":"https://api.github.com/users/cogneco/gists{/gist_id}","starred_url":"https://api.github.com/users/cogneco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cogneco/subscriptions","organizations_url":"https://api.github.com/users/cogneco/orgs","repos_url":"https://api.github.com/users/cogneco/repos","events_url":"https://api.github.com/users/cogneco/events{/privacy}","received_events_url":"https://api.github.com/users/cogneco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cogneco/ooc-kean","description":"ooc port of parts of Kean.","fork":false,"url":"https://api.github.com/repos/cogneco/ooc-kean","forks_url":"https://api.github.com/repos/cogneco/ooc-kean/forks","keys_url":"https://api.github.com/repos/cogneco/ooc-kean/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cogneco/ooc-kean/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cogneco/ooc-kean/teams","hooks_url":"https://api.github.com/repos/cogneco/ooc-kean/hooks","issue_events_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/events{/number}","events_url":"https://api.github.com/repos/cogneco/ooc-kean/events","assignees_url":"https://api.github.com/repos/cogneco/ooc-kean/assignees{/user}","branches_url":"https://api.github.com/repos/cogneco/ooc-kean/branches{/branch}","tags_url":"https://api.github.com/repos/cogneco/ooc-kean/tags","blobs_url":"https://api.github.com/repos/cogneco/ooc-kean/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cogneco/ooc-kean/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cogneco/ooc-kean/git/refs{/sha}","trees_url":"https://api.github.com/repos/cogneco/ooc-kean/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cogneco/ooc-kean/statuses/{sha}","languages_url":"https://api.github.com/repos/cogneco/ooc-kean/languages","stargazers_url":"https://api.github.com/repos/cogneco/ooc-kean/stargazers","contributors_url":"https://api.github.com/repos/cogneco/ooc-kean/contributors","subscribers_url":"https://api.github.com/repos/cogneco/ooc-kean/subscribers","subscription_url":"https://api.github.com/repos/cogneco/ooc-kean/subscription","commits_url":"https://api.github.com/repos/cogneco/ooc-kean/commits{/sha}","git_commits_url":"https://api.github.com/repos/cogneco/ooc-kean/git/commits{/sha}","comments_url":"https://api.github.com/repos/cogneco/ooc-kean/comments{/number}","issue_comment_url":"https://api.github.com/repos/cogneco/ooc-kean/issues/comments{/number}","contents_url":"https://api.github.com/repos/cogneco/ooc-kean/contents/{+path}","compare_url":"https://api.github.com/repos/cogneco/ooc-kean/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cogneco/ooc-kean/merges","archive_url":"https://api.github.com/repos/cogneco/ooc-kean/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cogneco/ooc-kean/downloads","issues_url":"https://api.github.com/repos/cogneco/ooc-kean/issues{/number}","pulls_url":"https://api.github.com/repos/cogneco/ooc-kean/pulls{/number}","milestones_url":"https://api.github.com/repos/cogneco/ooc-kean/milestones{/number}","notifications_url":"https://api.github.com/repos/cogneco/ooc-kean/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cogneco/ooc-kean/labels{/name}","releases_url":"https://api.github.com/repos/cogneco/ooc-kean/releases{/id}","created_at":"2014-10-15T13:42:17Z","updated_at":"2015-05-08T13:13:16Z","pushed_at":"2015-09-25T06:37:53Z","git_url":"git://github.com/cogneco/ooc-kean.git","ssh_url":"git@github.com:cogneco/ooc-kean.git","clone_url":"https://github.com/cogneco/ooc-kean.git","svn_url":"https://github.com/cogneco/ooc-kean","homepage":"","size":15226,"stargazers_count":3,"watchers_count":3,"language":"ooc","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":11,"forks":16,"open_issues":11,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423"},"html":{"href":"https://github.com/cogneco/ooc-kean/pull/423"},"issue":{"href":"https://api.github.com/repos/cogneco/ooc-kean/issues/423"},"comments":{"href":"https://api.github.com/repos/cogneco/ooc-kean/issues/423/comments"},"review_comments":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423/comments"},"review_comment":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cogneco/ooc-kean/pulls/423/commits"},"statuses":{"href":"https://api.github.com/repos/cogneco/ooc-kean/statuses/f6825ce23e46ed28cb21a127bfb0711def058b28"}}}}