Skip to content

Instantly share code, notes, and snippets.

@mzaks
Created October 21, 2016 13:36
Show Gist options
  • Select an option

  • Save mzaks/a92b1c2d922a311b528d1c03a9cdc032 to your computer and use it in GitHub Desktop.

Select an option

Save mzaks/a92b1c2d922a311b528d1c03a9cdc032 to your computer and use it in GitHub Desktop.
struct IsItPlugedIn : Action {
var counter = Counter()
func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) {
let realy = [String](repeating: " realy", count: counter.count).joined(separator: ",")
print("Is it\(realy) plugged in?")
counter.increase()
callback(data, .succeeded)
}
}
struct RepeatOnSuccess : Decorator {
let node : BehaviourNode
let counter = Counter()
func execute(data: DataType, callback: @escaping (DataType, BehaviourResult) -> ()) {
func repeatExecution(data : DataType, result : BehaviourResult) -> (){
if result == .succeeded {
if counter.count < 3 {
counter.increase()
} else {
print("Sorry can't help you mate.")
callback(data, .panicked(reason: "This is pointless"))
return
}
node.execute(data: data, callback: repeatExecution)
} else {
callback(data, result)
}
}
node.execute(data: data, callback: repeatExecution)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment