diff --git a/README.md b/README.md index f8c8f62..9d871cf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ ![nact Logo](https://raw.githubusercontent.com/ncthbrt/nact/master/assets/logo.svg?sanitize=true) **nact โ‡’ node.js + actors**\ - *your services have never been so ยต* @@ -126,6 +125,14 @@ const statefulGreeter = spawn( If no state is returned or the state returned is `undefined` or `null`, stateful actors automatically shut down. +Another feature of stateful actors is that you can subscribe to state changes by using the `state$` object. `state$` is a [RxJS](http://reactivex.io/rxjs/manual/index.html) observable stream, which makes it very composable. You can map, filter, combine, throttle and perform many other operations on the stream. For example, you could create a subscription to the statefulGreeter which prints a count of the number of unique names which have been greeted: + +```js +statefulGreeter.state$ + .map(state => Object.keys(state).length) + .subscribe(count => console.log(`The statefulGreeter has now greeted ${count} unique names`); +``` + ## Actor Communication [![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/remix/nact-ping-pong) @@ -334,10 +341,6 @@ The application we made in the [querying](#querying) section isn't very useful. Actors can create child actors of their own, and accordingly every actor has a parent. Up till now we've been creating actors which are children of the actor system (which is a pseudo actor). However in a real system, this would be considered an anti pattern, for much the same reasons as placing all your code in a single file is an anti-pattern. By exploiting the actor hierarchy, you can enforce a separation of concerns and encapsulate system functionality, while providing a coherent means of dealing with failure and system shutdown. - - - - Example of an Actor System Hierarchy # Persistence @@ -372,4 +375,4 @@ sender dispatch recovering -โ€‹ \ No newline at end of file +โ€‹