mirror of
https://github.com/blindlobstar/go-interview-problems
synced 2025-04-25 11:15:15 +00:00
32 lines
818 B
Go
32 lines
818 B
Go
package main
|
|
|
|
type Connection interface {
|
|
// Need call Connect before Send
|
|
// Take time to connect
|
|
Connect()
|
|
|
|
// Every connection should be disconnected after use
|
|
// Take time to disconnect
|
|
Disconnect()
|
|
|
|
Send(req string) (string, error)
|
|
}
|
|
|
|
type ConnectionCreator interface {
|
|
// Create new connection
|
|
// Will return error if there is more than maxConn
|
|
NewConnection() (Connection, error)
|
|
}
|
|
|
|
type Saver interface {
|
|
// Saves data to unsafe storage
|
|
// WILL CORRUPT DATA on concurrent save
|
|
Save(data string)
|
|
}
|
|
|
|
// SendAndSave should send all requests concurrently using at most `maxConn` simultaneous connections.
|
|
// Responses must be saved using Saver.Save.
|
|
// Be careful: Saver.Save is not safe for concurrent use.
|
|
func SendAndSave(creator ConnectionCreator, saver Saver, requests []string, maxConn int) {
|
|
}
|