-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
Description
Currently, Action needs to call dispatcher.dispatch for async func.
For example.
func invoke(dispatcher: Dispatcher) {
dispatcher.dispatch(self, result: Result(value: result))
}It has some problem.
There is possibilities which developer forgets call dispatch.
And I want to hide dispatcher instance from action.
This is my ideal.
func invoke() -> Payload {
let payload = anyFunc()
return payload
}This approach is more robust because compiler warns about missing return value and its type.
However, it is difficult because async func can't return value immediately.
My idea is this.
struct ActionA: Action {
typealias Payload = Todo
func invoke() throws -> Payload {
return Todo()
}
}
struct ActionB: AsyncAction {
typealias Payload = Todo
func invoke() -> Promise<Payload> {
return Promise { fulfill, reject in
asyncCall() { (todo) in
fulfill(todo)
}
}
}
}So, divide action to normal and async.
Action can return payload immediately.
AsyncAction action uses Promise like as PromiseKit
Any idea?