forawait (let data of socket.receiver('foo')) { console.log("forawait -> data", data) } })();
} })();
frondend
1 2 3 4 5
let socket = socketClusterClient.create();
forawait (let event of socket.listener('connect')) { socket.transmit('foo', 123); }
上述程式碼執行的時候
Backend 會因為 await sleep(); 非同步問題
socket.receiver('foo') 在非同步之後
會無法執行到 console.log("forawait -> data", data)
所有的情境都會造成訊息的丟失
所以需要做一些調整
調整後
如果只是調整順序的話並不能解決問題
Backend
Bad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
(async () => { forawait (let {socket} of agServer.listener('connection')) {
(async () => { // This will not work because the iterator is not yet created at this point. let fooStream = socket.receiver('foo');
// If any messages arrive during this time, they will be ignored! awaitdoSomethingWhichTakesAFewSeconds();
// The iterator gets created (and starts buffering) here! forawait (let data of fooStream) { // ... } })();
} })();
Backend
Good
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(async () => { forawait (let {socket} of agServer.listener('connection')) {
(async () => { // This will create a consumable which will start buffering messages immediately. let fooStreamConsumable = socket.receiver('foo').createConsumer();
awaitsleep();
// This loop will start from the beginning of the buffer. forawait (let data of fooStreamConsumable) { console.log("forawait -> data", data) } })();
After you create the Swift file, you should be prompted to choose if you want to configure an Objective-C Bridging Header. Select “Create Bridging Header”.
If you have to send any data to a RCTDirectEventBlock method, you must return a [AnyHashable:Any] structure. This means that you can’t pass a String or Int directly, you have to put them in a Dictionary.
[2019-06-03T07:54:26.366Z] INFO ********/BROKER: Moleculer v0.13.9 is starting... [2019-06-03T07:54:26.369Z] INFO ********/BROKER: Node ID: ******** [2019-06-03T07:54:26.370Z] INFO ********/BROKER: Namespace: <not defined> [2019-06-03T07:54:26.370Z] INFO ********/REGISTRY: Strategy: RoundRobinStrategy [2019-06-03T07:54:26.372Z] INFO ********/BROKER: Serializer: JSONSerializer [2019-06-03T07:54:26.373Z] INFO ********/BROKER: Registered 10 internal middleware(s). [2019-06-03T07:54:26.390Z] INFO ********/REGISTRY: '$node' service is registered. [2019-06-03T07:54:26.392Z] INFO ********/REGISTRY: 'math' service is registered. [2019-06-03T07:54:26.394Z] INFO ********/BROKER: ServiceBroker with 2 service(s) is started successfully. 5 + 3 = 8 [2019-06-03T07:54:26.400Z] INFO ********/BROKER: ServiceBroker is stopped. Good bye.
? Add API Gateway (moleculer-web) service? // 是否使用 api gateway ? Would you like to communicate with other nodes? // 是否需要和其他 nodes 溝通 ? Select a transporter NATS (recommended) // 使用哪一種 transporter 工具 ? Would you like to use cache? 是否要使用 cache ? Select a cacher solution ? Add Docker files? 是否要使用 Docker ? Use ESLint to lint your code? 是否使用 ESLint ? Setup unit tests with Jest? Unitest framework Create'moleculerdemo' folder... ? Would you like to run 'npm install'?
module.exports={ name:"api", mixins: [ApiGwService] settings:{ // Change port setting port:8080 }, actions:{ myAction() { // Add a new action to apiGwService service } } }
constSpecificPlatformComponent = Platform.select({ ios: () =><Text>I am use IOS</Text>, android: () =><Text>I am use Android</Text>, });
exportdefaultclassAppextendsReact.Component { render() { return ( <Viewstyle={styles.container}> <Text>Open up App.js to start working on your app!</Text> <SpecificPlatformComponent /> </View> ); } }
constSpecificPlatformComponent = Platform.select({ ios: () =><Text>I am use IOS</Text>, android: () =><Text>I am use Android</Text>, });
constSpecificPlatformVersionComponent = Platform.select({ ios: () =><Text>my Iphone Version is {Platform.Version}</Text>, android: () =><Text>my Android Version is {Platform.Version}</Text>, });
exportdefaultclassAppextendsReact.Component { render() { return ( <Viewstyle={styles.container}> <Text>Open up App.js to start working on your app!</Text> <SpecificPlatformComponent /> <SpecificPlatformVersionComponent /> </View> ); } }