{"action":"created","issue":{"url":"https://api.github.com/repos/advantageous/qbit/issues/746","repository_url":"https://api.github.com/repos/advantageous/qbit","labels_url":"https://api.github.com/repos/advantageous/qbit/issues/746/labels{/name}","comments_url":"https://api.github.com/repos/advantageous/qbit/issues/746/comments","events_url":"https://api.github.com/repos/advantageous/qbit/issues/746/events","html_url":"https://github.com/advantageous/qbit/issues/746","id":163598216,"number":746,"title":"Promises vs Callbacks. Callbacks win","user":{"login":"revelfire","id":2252543,"avatar_url":"https://avatars.githubusercontent.com/u/2252543?v=3","gravatar_id":"","url":"https://api.github.com/users/revelfire","html_url":"https://github.com/revelfire","followers_url":"https://api.github.com/users/revelfire/followers","following_url":"https://api.github.com/users/revelfire/following{/other_user}","gists_url":"https://api.github.com/users/revelfire/gists{/gist_id}","starred_url":"https://api.github.com/users/revelfire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/revelfire/subscriptions","organizations_url":"https://api.github.com/users/revelfire/orgs","repos_url":"https://api.github.com/users/revelfire/repos","events_url":"https://api.github.com/users/revelfire/events{/privacy}","received_events_url":"https://api.github.com/users/revelfire/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-04T03:44:10Z","updated_at":"2016-07-05T19:09:00Z","closed_at":null,"body":"Love the new API for for Promises.  However they aren't yet working right.  Using 10.10.6.\r\n\r\nThis works:\r\n\r\n```\r\npublic final void listFeeds(Callback<List<FeedMeta>> cb, @PathVariable Plan plan, @PathVariable String clientId) {\r\n        try {\r\n            for (FeedMeta feed : feedMetaList) {\r\n                try {\r\n                    feed.setReferenceId(feeds().getFeed(feed.getFeedSource()).getMaxId());\r\n                } catch (Exception e) {\r\n                    feed.setReferenceId(\"-1\");\r\n                }\r\n\r\n            }\r\n            cb.resolve(feedMetaList);\r\n        } catch (Exception e) {\r\n            cb.reject(e);\r\n        }\r\n    }\r\n```\r\n\r\nThis does not:\r\n\r\n```\r\npublic final Promise<List<FeedMeta>> listFeeds(@PathVariable Plan plan, @PathVariable String clientId) {\r\n\r\n        return invokablePromise(listPromise -> {\r\n            try {\r\n                for (FeedMeta feed : feedMetaList) {\r\n                    try {\r\n                        feed.setReferenceId(feeds().getFeed(feed.getFeedSource()).getMaxId());\r\n                    } catch (Exception e) {\r\n                        feed.setReferenceId(\"-1\");\r\n                    }\r\n\r\n                }\r\n                listPromise.resolve(feedMetaList);\r\n            } catch (Exception e) {\r\n                listPromise.reject(e);\r\n            }\r\n        });\r\n    }\r\n\r\n```\r\nLet me know if you need more info."},"comment":{"url":"https://api.github.com/repos/advantageous/qbit/issues/comments/230573007","html_url":"https://github.com/advantageous/qbit/issues/746#issuecomment-230573007","issue_url":"https://api.github.com/repos/advantageous/qbit/issues/746","id":230573007,"user":{"login":"RichardHightower","id":382678,"avatar_url":"https://avatars.githubusercontent.com/u/382678?v=3","gravatar_id":"","url":"https://api.github.com/users/RichardHightower","html_url":"https://github.com/RichardHightower","followers_url":"https://api.github.com/users/RichardHightower/followers","following_url":"https://api.github.com/users/RichardHightower/following{/other_user}","gists_url":"https://api.github.com/users/RichardHightower/gists{/gist_id}","starred_url":"https://api.github.com/users/RichardHightower/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RichardHightower/subscriptions","organizations_url":"https://api.github.com/users/RichardHightower/orgs","repos_url":"https://api.github.com/users/RichardHightower/repos","events_url":"https://api.github.com/users/RichardHightower/events{/privacy}","received_events_url":"https://api.github.com/users/RichardHightower/received_events","type":"User","site_admin":false},"created_at":"2016-07-05T19:09:00Z","updated_at":"2016-07-05T19:09:00Z","body":"Ok... I got all three to work... I was calling the wrong method on the serviceBundle to start it, which indicates, the method to start is confusing. (Good grief... )\r\n\r\nNow all three work.\r\n\r\n\r\n```java\r\npackage io.advantageous.qbit.vertx.bugs;\r\n\r\nimport io.advantageous.qbit.client.Client;\r\nimport io.advantageous.qbit.client.ClientBuilder;\r\nimport io.advantageous.qbit.server.EndpointServerBuilder;\r\nimport io.advantageous.qbit.server.ServiceEndpointServer;\r\nimport io.advantageous.qbit.service.*;\r\nimport io.advantageous.qbit.util.PortUtils;\r\nimport io.advantageous.reakt.promise.Promise;\r\nimport io.advantageous.reakt.promise.Promises;\r\nimport org.junit.Test;\r\n\r\nimport java.time.Duration;\r\nimport java.util.Collections;\r\nimport java.util.List;\r\n\r\nimport static junit.framework.Assert.assertEquals;\r\nimport static junit.framework.Assert.assertNotNull;\r\n\r\npublic class Bug746 {\r\n\r\n\r\n    public static class FeedMeta {\r\n        private final String name;\r\n\r\n        public FeedMeta(String name) {\r\n            this.name = name;\r\n        }\r\n    }\r\n\r\n    public interface FeedService {\r\n        Promise<List<FeedMeta>> listFeeds();\r\n\r\n    }\r\n\r\n    public static class FeedServiceImpl implements FeedService {\r\n\r\n        public Promise<List<FeedMeta>> listFeeds() {\r\n            return Promises.invokablePromise(promise -> {\r\n                promise.resolve(Collections.singletonList(new FeedMeta(\"Hello\")));\r\n            });\r\n        }\r\n\r\n    }\r\n\r\n    @Test //Works\r\n    public void testWithServiceQueue() {\r\n        final ServiceQueue serviceQueue = ServiceBuilder.serviceBuilder()\r\n                .setServiceObject(new FeedServiceImpl()).buildAndStartAll();\r\n        final FeedService feedService = serviceQueue.createProxyWithAutoFlush(FeedService.class, Duration.ofMillis(100));\r\n\r\n        final List<FeedMeta> feedMetas = feedService.listFeeds()\r\n                .invokeAsBlockingPromise(Duration.ofSeconds(30)).get();\r\n\r\n        assertNotNull(feedMetas);\r\n        assertEquals(1, feedMetas.size());\r\n\r\n        assertEquals(\"Hello\", feedMetas.get(0).name);\r\n\r\n        serviceQueue.stop();\r\n    }\r\n\r\n    @Test //Works\r\n    public void testWithServiceBundle() {\r\n\r\n        final ServiceBundleBuilder serviceBundleBuilder = ServiceBundleBuilder.serviceBundleBuilder();\r\n\r\n        final ServiceBundle serviceBundle = serviceBundleBuilder.build().startServiceBundle();\r\n\r\n        serviceBundle.addServiceObject(\"foo\", new FeedServiceImpl());\r\n\r\n        final FeedService feedService = serviceBundle.createLocalProxy(FeedService.class, \"foo\");\r\n\r\n        final Promise<List<FeedMeta>> listPromise = feedService.listFeeds()\r\n                .invokeAsBlockingPromise(Duration.ofSeconds(30));\r\n\r\n        ServiceProxyUtils.flushServiceProxy(feedService);\r\n\r\n\r\n        final List<FeedMeta> feedMetas = listPromise.get();\r\n\r\n\r\n\r\n        assertNotNull(feedMetas);\r\n        assertEquals(1, feedMetas.size());\r\n\r\n        assertEquals(\"Hello\", feedMetas.get(0).name);\r\n\r\n        serviceBundle.stop();\r\n    }\r\n\r\n    @Test //Works\r\n    public void testWithClient() {\r\n\r\n\r\n        int port = PortUtils.findOpenPortStartAt(9999);\r\n        final ServiceEndpointServer serviceEndpointServer =\r\n                EndpointServerBuilder.endpointServerBuilder().setPort(port)\r\n                        .addService(\"foo\", new FeedServiceImpl()).build().startServerAndWait();\r\n\r\n\r\n\r\n        final Client client = ClientBuilder.clientBuilder().setPort(port).build().startClient();\r\n\r\n        final FeedService feedService = client.createProxy(FeedService.class, \"foo\");\r\n\r\n\r\n        final List<FeedMeta> feedMetas = feedService.listFeeds()\r\n                .invokeAsBlockingPromise(Duration.ofSeconds(30)).get();\r\n\r\n\r\n        assertNotNull(feedMetas);\r\n        assertEquals(1, feedMetas.size());\r\n\r\n        assertEquals(\"Hello\", feedMetas.get(0).name);\r\n\r\n        serviceEndpointServer.stop();\r\n        client.stop();\r\n    }\r\n\r\n}\r\n\r\n```"}}
{"actor":{"display_login":"RichardHightower"}}