F# script to application
I have written two small scr开发者_如何学Goipts,
First one maintains a dictionary of current stock prices for a set of securities. I am using recursion to listen to a named pipe. Whenever there is something available on the name pipe, it updates the security price and goes right back and start listening to the pipe.
The second one periodically reads the stock price of some security from the price cache of the first program and performs come calculation.
But I have no idea how to make these two programs communicate. I somehow need to make my second programs start the first program and let it run in the background and get the price whenever it needs it.
Can someone point me in the right direction?
Thank you, -Sudaly
Do they have to be separate programs/scripts?
If not, I would put them in the same program and use async/agents to run the two tasks.
Here's a starter-blog for that strategy:
Link
Basically one agent just sits in a loop: async read from pipe, update price
The other agent sits in a loop: sleep for some time, read price and do calculation. Alternatively this could just be the synchronous 'main program' loop.
(Depending on data structure, you may or may not need coordination to deal with one agent reading while other is updating.)
Actually, you don't even need an agent, can just have async that runs in background. Something like
// first script
let mutable lastPrice = 0.0
async {
while true do
let! nextval = namedPipe.AsyncRead()
lastPrice <- nextVal
} |> Async.Start
// second script
while true do
System.Threading.Thread.Sleep(1000)
printfn "%f" (calc lastPrice)
if that helps.
There are many ways.
- .Net Remoting
- Pipes
- Text files on disk
- intermediary service (web or local)
- wcf
精彩评论