{"action":"created","comment":{"url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/comments/174141922","pull_request_review_id":103442700,"id":174141922,"diff_hunk":"@@ -0,0 +1,117 @@\n+/*\n+ * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+import {EventEmitter} from 'events';\n+import * as Long from 'long';\n+import * as Promise from 'bluebird';\n+\n+export class Batch {\n+    private base: Long;\n+    private increment: Long;\n+    private batchSize: number;\n+    private invalidSince: Long;\n+    private lastIndex: number = 0;\n+\n+    constructor(validityMillis: Long, base: Long, increment: Long, batchSize: number) {\n+        this.base = base;\n+        this.increment = increment;\n+        this.batchSize = batchSize;\n+        if (validityMillis.greaterThan(0)) {\n+            this.invalidSince = validityMillis.add(Date.now());\n+        } else {\n+            this.invalidSince = Long.MAX_VALUE;\n+        }\n+    }\n+\n+    /**\n+     * @returns next id from the batch,\n+     *          undefined if ids are exhausted or not valid anymore\n+     */\n+    nextId(): Long {\n+        if (this.invalidSince.lessThanOrEqual(Date.now())) {\n+            return undefined;\n+        }\n+        if (this.lastIndex === this.batchSize) {\n+            return undefined;\n+        }\n+        let returnLong = this.base.add(this.increment.multiply(this.lastIndex));\n+        this.lastIndex++;\n+        return returnLong;\n+    }\n+}\n+\n+export class AutoBatcher {\n+\n+    private readonly NEW_BATCH_AVAILABLE = 'newBatch';\n+\n+    private quee: Array<Promise.Resolver<Long>> = [];\n+    private batch: Batch;\n+    private requestInFlight: boolean = false;\n+    private supplier: () => Promise<any>;\n+    private validMilliseconds: Long;\n+    private emitter = new EventEmitter();\n+\n+    constructor(validMilliseconds: Long, supplier: () => Promise<any>) {\n+        this.validMilliseconds = validMilliseconds;\n+        this.supplier = supplier;\n+        this.emitter.on(this.NEW_BATCH_AVAILABLE, this.processIdRequests.bind(this));\n+        this.emitter.on('error', this.rejectAll.bind(this));","path":"src/proxy/flakeid/AutoBatcher.ts","position":71,"original_position":71,"commit_id":"dde1d0592142a21bd04f8ad8256763282e268bf9","original_commit_id":"dde1d0592142a21bd04f8ad8256763282e268bf9","user":{"login":"mustafaiman","id":6582349,"avatar_url":"https://avatars3.githubusercontent.com/u/6582349?v=4","gravatar_id":"","url":"https://api.github.com/users/mustafaiman","html_url":"https://github.com/mustafaiman","followers_url":"https://api.github.com/users/mustafaiman/followers","following_url":"https://api.github.com/users/mustafaiman/following{/other_user}","gists_url":"https://api.github.com/users/mustafaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mustafaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mustafaiman/subscriptions","organizations_url":"https://api.github.com/users/mustafaiman/orgs","repos_url":"https://api.github.com/users/mustafaiman/repos","events_url":"https://api.github.com/users/mustafaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mustafaiman/received_events","type":"User","site_admin":false},"body":"@viliam-durina the operation is already retried by Invocation Service before `this.emitter` emits an error. I do not see any additional retry logic in Java client's FlakeIdGenerator.","created_at":"2018-03-13T14:04:32Z","updated_at":"2018-03-13T14:04:33Z","html_url":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276#discussion_r174141922","pull_request_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/comments/174141922"},"html":{"href":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276#discussion_r174141922"},"pull_request":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276"}},"in_reply_to_id":174123750},"pull_request":{"url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276","id":173851663,"html_url":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276","diff_url":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276.diff","patch_url":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276.patch","issue_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/276","number":276,"state":"open","locked":false,"title":"Enhancement/flakeid","user":{"login":"mustafaiman","id":6582349,"avatar_url":"https://avatars3.githubusercontent.com/u/6582349?v=4","gravatar_id":"","url":"https://api.github.com/users/mustafaiman","html_url":"https://github.com/mustafaiman","followers_url":"https://api.github.com/users/mustafaiman/followers","following_url":"https://api.github.com/users/mustafaiman/following{/other_user}","gists_url":"https://api.github.com/users/mustafaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mustafaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mustafaiman/subscriptions","organizations_url":"https://api.github.com/users/mustafaiman/orgs","repos_url":"https://api.github.com/users/mustafaiman/repos","events_url":"https://api.github.com/users/mustafaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mustafaiman/received_events","type":"User","site_admin":false},"body":"FlakeIdGenerator implementation + test + doc + code sample","created_at":"2018-03-08T21:12:09Z","updated_at":"2018-03-13T14:04:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8cd1eb511e0a5446041d4ced9b14cb9014119f3d","assignee":null,"assignees":[],"requested_reviewers":[{"login":"sancar","id":570462,"avatar_url":"https://avatars0.githubusercontent.com/u/570462?v=4","gravatar_id":"","url":"https://api.github.com/users/sancar","html_url":"https://github.com/sancar","followers_url":"https://api.github.com/users/sancar/followers","following_url":"https://api.github.com/users/sancar/following{/other_user}","gists_url":"https://api.github.com/users/sancar/gists{/gist_id}","starred_url":"https://api.github.com/users/sancar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sancar/subscriptions","organizations_url":"https://api.github.com/users/sancar/orgs","repos_url":"https://api.github.com/users/sancar/repos","events_url":"https://api.github.com/users/sancar/events{/privacy}","received_events_url":"https://api.github.com/users/sancar/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":279734123,"url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/labels/Type:%20Enhancement","name":"Type: Enhancement","color":"5319e7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276/commits","review_comments_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276/comments","review_comment_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/276/comments","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/statuses/dde1d0592142a21bd04f8ad8256763282e268bf9","head":{"label":"mustafaiman:enhancement/flakeid","ref":"enhancement/flakeid","sha":"dde1d0592142a21bd04f8ad8256763282e268bf9","user":{"login":"mustafaiman","id":6582349,"avatar_url":"https://avatars3.githubusercontent.com/u/6582349?v=4","gravatar_id":"","url":"https://api.github.com/users/mustafaiman","html_url":"https://github.com/mustafaiman","followers_url":"https://api.github.com/users/mustafaiman/followers","following_url":"https://api.github.com/users/mustafaiman/following{/other_user}","gists_url":"https://api.github.com/users/mustafaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mustafaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mustafaiman/subscriptions","organizations_url":"https://api.github.com/users/mustafaiman/orgs","repos_url":"https://api.github.com/users/mustafaiman/repos","events_url":"https://api.github.com/users/mustafaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mustafaiman/received_events","type":"User","site_admin":false},"repo":{"id":48358918,"name":"hazelcast-nodejs-client","full_name":"mustafaiman/hazelcast-nodejs-client","owner":{"login":"mustafaiman","id":6582349,"avatar_url":"https://avatars3.githubusercontent.com/u/6582349?v=4","gravatar_id":"","url":"https://api.github.com/users/mustafaiman","html_url":"https://github.com/mustafaiman","followers_url":"https://api.github.com/users/mustafaiman/followers","following_url":"https://api.github.com/users/mustafaiman/following{/other_user}","gists_url":"https://api.github.com/users/mustafaiman/gists{/gist_id}","starred_url":"https://api.github.com/users/mustafaiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mustafaiman/subscriptions","organizations_url":"https://api.github.com/users/mustafaiman/orgs","repos_url":"https://api.github.com/users/mustafaiman/repos","events_url":"https://api.github.com/users/mustafaiman/events{/privacy}","received_events_url":"https://api.github.com/users/mustafaiman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mustafaiman/hazelcast-nodejs-client","description":"Hazelcast IMDG Node.js Client","fork":true,"url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client","forks_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/forks","keys_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/teams","hooks_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/hooks","issue_events_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/issues/events{/number}","events_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/events","assignees_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/assignees{/user}","branches_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/branches{/branch}","tags_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/tags","blobs_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/statuses/{sha}","languages_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/languages","stargazers_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/stargazers","contributors_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/contributors","subscribers_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/subscribers","subscription_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/subscription","commits_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/contents/{+path}","compare_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/merges","archive_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/downloads","issues_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/issues{/number}","pulls_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/pulls{/number}","milestones_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/milestones{/number}","notifications_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/labels{/name}","releases_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/releases{/id}","deployments_url":"https://api.github.com/repos/mustafaiman/hazelcast-nodejs-client/deployments","created_at":"2015-12-21T08:02:41Z","updated_at":"2018-01-05T08:46:28Z","pushed_at":"2018-03-12T21:51:59Z","git_url":"git://github.com/mustafaiman/hazelcast-nodejs-client.git","ssh_url":"git@github.com:mustafaiman/hazelcast-nodejs-client.git","clone_url":"https://github.com/mustafaiman/hazelcast-nodejs-client.git","svn_url":"https://github.com/mustafaiman/hazelcast-nodejs-client","homepage":"https://hazelcast.org/clients/node-js/","size":9137,"stargazers_count":0,"watchers_count":0,"language":"TypeScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hazelcast:master","ref":"master","sha":"55bffcffcbd53c46d7a9ad9454e7bc0d7791e976","user":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars2.githubusercontent.com/u/1453152?v=4","gravatar_id":"","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"repo":{"id":45202495,"name":"hazelcast-nodejs-client","full_name":"hazelcast/hazelcast-nodejs-client","owner":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars2.githubusercontent.com/u/1453152?v=4","gravatar_id":"","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hazelcast/hazelcast-nodejs-client","description":"Hazelcast IMDG Node.js Client","fork":false,"url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client","forks_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/forks","keys_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/teams","hooks_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/hooks","issue_events_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/events{/number}","events_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/events","assignees_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/assignees{/user}","branches_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/branches{/branch}","tags_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/tags","blobs_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/statuses/{sha}","languages_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/languages","stargazers_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/stargazers","contributors_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/contributors","subscribers_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/subscribers","subscription_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/subscription","commits_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/contents/{+path}","compare_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/merges","archive_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/downloads","issues_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues{/number}","pulls_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls{/number}","milestones_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/milestones{/number}","notifications_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/labels{/name}","releases_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/releases{/id}","deployments_url":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/deployments","created_at":"2015-10-29T18:24:48Z","updated_at":"2018-03-13T11:57:12Z","pushed_at":"2018-03-12T21:55:24Z","git_url":"git://github.com/hazelcast/hazelcast-nodejs-client.git","ssh_url":"git@github.com:hazelcast/hazelcast-nodejs-client.git","clone_url":"https://github.com/hazelcast/hazelcast-nodejs-client.git","svn_url":"https://github.com/hazelcast/hazelcast-nodejs-client","homepage":"https://hazelcast.org/clients/node-js/","size":9098,"stargazers_count":42,"watchers_count":42,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":32,"mirror_url":null,"archived":false,"open_issues_count":11,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":32,"open_issues":11,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276"},"html":{"href":"https://github.com/hazelcast/hazelcast-nodejs-client/pull/276"},"issue":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/276"},"comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/issues/276/comments"},"review_comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276/comments"},"review_comment":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/pulls/276/commits"},"statuses":{"href":"https://api.github.com/repos/hazelcast/hazelcast-nodejs-client/statuses/dde1d0592142a21bd04f8ad8256763282e268bf9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"mustafaiman"}}