generated from grepsedawk/sharded.cr
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw Physics::MovementStuck upon stuck movement
This allows the exception to be caught directly in bots
- Loading branch information
1 parent
d94f35c
commit 9a205f6
Showing
3 changed files
with
32 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
class Rosegold::Action(T) | ||
SUCCESS = "" # TODO use unique symbol | ||
|
||
# TODO try channel size 1 so #succeed/#fail aren't rendezvous | ||
getter channel : Channel(String) = Channel(String).new | ||
getter channel : Channel(Exception | Nil) = Channel(Exception | Nil).new | ||
getter target : T | ||
|
||
def initialize(@target : T); end | ||
|
||
def succeed | ||
@channel.send(SUCCESS) | ||
@channel.send nil | ||
end | ||
|
||
def fail(msg : String) | ||
@channel.send(msg) | ||
@channel.send Exception.new msg | ||
end | ||
|
||
def fail(exception : Exception) | ||
@channel.send exception | ||
end | ||
|
||
# Throw error if it failed | ||
def join | ||
result = channel.receive | ||
raise Exception.new(result) if result != Action::SUCCESS | ||
raise result if result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters