Remove asynchronous channel on RESTStorage interfaces

This commit is contained in:
Clayton Coleman
2015-02-10 09:26:26 -05:00
parent d167c11b59
commit 79cb93002e
6 changed files with 88 additions and 134 deletions

View File

@@ -45,28 +45,3 @@ func MakeAsync(fn WorkFunc) <-chan RESTResult {
}()
return channel
}
// WorkFunc is used to perform any time consuming work for an api call, after
// the input has been validated. Pass one of these to MakeAsync to create an
// appropriate return value for the Update, Delete, and Create methods.
type WorkResultFunc func() (result RESTResult, err error)
// MakeAsync takes a function and executes it, delivering the result in the way required
// by RESTStorage's Update, Delete, and Create methods.
func MakeAsyncResult(fn WorkResultFunc) <-chan RESTResult {
channel := make(chan RESTResult)
go func() {
defer util.HandleCrash()
obj, err := fn()
if err != nil {
channel <- RESTResult{Object: errToAPIStatus(err)}
} else {
channel <- obj
}
// 'close' is used to signal that no further values will
// be written to the channel. Not strictly necessary, but
// also won't hurt.
close(channel)
}()
return channel
}