Skip to content

Instantly share code, notes, and snippets.

@object
Created June 1, 2016 16:48
Show Gist options
  • Select an option

  • Save object/2512c85c96369011b69e53a3b3d06102 to your computer and use it in GitHub Desktop.

Select an option

Save object/2512c85c96369011b69e53a3b3d06102 to your computer and use it in GitHub Desktop.
let sftpActor (clientFactory : IClientFactory) (mailbox: Actor<_>) =
let rec disconnected () =
actor {
let! message = mailbox.Receive ()
match message with
| Connect ->
let connection = clientFactory.CreateSftpClient()
connection.Connect()
return! connected (connection)
| _ ->
cprintfn ConsoleColor.Yellow "Sftp: invalid operation in disconnected state: %A" message
return! disconnected ()
}
and connected (connection) =
actor {
let! message = mailbox.Receive ()
match message with
| Disconnect ->
connection.Disconnect()
connection.Dispose()
return! disconnected ()
| _ ->
cprintfn ConsoleColor.Yellow "Sftp: invalid operation in connected state: %A" message
return! connected (connection)
}
disconnected ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment