Created
September 12, 2013 17:19
-
-
Save carbonrobot/6540972 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Ticker = function () { | |
| var decay = 5.0; | |
| var growth = 7.0; | |
| var stocks = [ | |
| { name: "Apple", price: 4.50 }, | |
| { name: "Microsoft", price: 4.00 }, | |
| { name: "Facebook", price: 3.75 } | |
| ]; | |
| var _state = 'Not Started'; | |
| this.execute = function (self) { | |
| _state = 'Processing'; | |
| stocks.forEach(function (p, i) { | |
| p.Price -= p.Price / decay; | |
| }); | |
| process.send({ stocks: stocks }); | |
| if (!self) | |
| self = this; | |
| if(_state !== 'Cancelled') | |
| setTimeout(function () { | |
| self.execute(self); | |
| }, 1000); | |
| }; | |
| this.stop = function () { | |
| _state = 'Cancelled'; | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment