On the other side we have the function B. Again it doesn't know who will receive it. Then it makes its request by sending out CALCULATE_FIBONACCI. It just knows that it will come with a index and a number. A needs the Fibonacci number so it subscribes to a messaged called FIBONACCI_NUMBER. We will see the implementation of the Bus in a bit but before that let's focus on how A and B uses it. We will start with the following: async function A(n) `) īus.send('FIBONACCI_NUMBER', n, fibonacci(n)) We will also assume that B does the calculation asynchronously. Our function A receives the index and B knows how to calculate the number behind that index in the sequence. We will assume that the goal of this example is to calculate a Fibonacci sequence number where our sequence looks like that 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. We have data to pass back and forth and we have logic that needs to run in a specific order. So, in such situation we have to think about two things - communication and synchronization. We can say that A will probably trigger B by passing what it knows and will consume what B returns. These two functions depend on each other. The result of the second one B is required by the first one to continue working. The first one knows something that the second one needs in order to do its job. Let's say that we have two functions - A and B.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |