Skip to content

Commit

Permalink
Do not detach in sample code
Browse files Browse the repository at this point in the history
the sample code should be batteries included ready to go
putting the detach sample in a ruby file and running it
does not keep running
  • Loading branch information
ChillerDragon committed Sep 17, 2023
1 parent 27bfbc2 commit 59240fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions docs/v0.0.1/classes/TeeworldsClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ client.on_input_timing do |context|
puts "time_left: #{context.message.time_left}"
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_maplist_entry_rem"></a> #on_maplist_entry_rem(&block)
Expand All @@ -34,7 +34,7 @@ client.on_maplist_entry_rem do |context|
puts context.message.name
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_maplist_entry_add"></a> #on_maplist_entry_add(&block)
Expand All @@ -53,7 +53,7 @@ client.on_maplist_entry_add do |context|
puts context.message.name
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_rcon_cmd_rem"></a> #on_rcon_cmd_rem(&block)
Expand All @@ -70,7 +70,7 @@ client.on_rcon_cmd_rem do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_rcon_cmd_add"></a> #on_rcon_cmd_add(&block)
Expand All @@ -87,7 +87,7 @@ client.on_rcon_cmd_add do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_auth_off"></a> #on_auth_off(&block)
Expand All @@ -104,7 +104,7 @@ client.on_auth_off do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_auth_on"></a> #on_auth_on(&block)
Expand All @@ -121,7 +121,7 @@ client.on_auth_on do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_snapshot"></a> #on_snapshot(&block)
Expand All @@ -138,7 +138,7 @@ client.on_snapshot do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_rcon_line"></a> #on_rcon_line(&block)
Expand All @@ -155,7 +155,7 @@ client.on_rcon_line do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_disconnect"></a> #on_disconnect(&block)
Expand All @@ -172,7 +172,7 @@ client.on_disconnect do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_connected"></a> #on_connected(&block)
Expand All @@ -189,7 +189,7 @@ client.on_connected do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_client_info"></a> #on_client_info(&block)
Expand All @@ -206,7 +206,7 @@ client.on_client_info do |context|
# TODO: generated documentation
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_chat"></a> #on_chat(&block)
Expand All @@ -227,7 +227,7 @@ client.on_chat do |context, msg|
puts "[chat] #{msg}"
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```
### <a name="on_map_change"></a> #on_map_change(&block)

Expand All @@ -248,7 +248,7 @@ client.on_map_change do |context|
context.cancel
end

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
```

### <a name="on_client_drop"></a> #on_client_drop(&block)
Expand Down Expand Up @@ -292,7 +292,7 @@ end
Connect to given server. The option ``:detach`` decides wether the connection should run in a background thread or not.
By default no thread will be spawned. And the ``connect()`` method blocks your main thread. Meaning no line below that will be run as long as the connection is up.

If you decide to provide the option ``detach: true`` it will spawn a thread and run the connection in there. Meaning it will jump to the next line after ``connect()`` is called. So it is your responsibility to keep the program running.
If you decide to provide the option ``detach: false`` it will spawn a thread and run the connection in there. Meaning it will jump to the next line after ``connect()`` is called. So it is your responsibility to keep the program running.
If the connection happens in the last line of your program it will just quit. So you have to keep it up using a loop for example.

**Example:**
Expand All @@ -301,7 +301,7 @@ If the connection happens in the last line of your program it will just quit. So
client = TeeworldsClient.new(verbose: true)

# this will spawn a background thread
client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)
# this line will be run directly after the connection

# this line will be running as long as the connection is up
Expand All @@ -321,7 +321,7 @@ Send a chat message. Takes the chat message as String.
```ruby
client = TeeworldsClient.new(verbose: true)

client.connect('localhost', 8303, detach: true)
client.connect('localhost', 8303, detach: false)

client.send_chat('hello world!')
```
2 changes: 1 addition & 1 deletion scripts/hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function add_hook_doc() {
fi
local tmpdoc
local obj_var=client
local run="client.connect('localhost', 8303, detach: true)"
local run="client.connect('localhost', 8303, detach: false)"
if [[ "$ruby_class" =~ Server ]]
then
obj_var=server
Expand Down

0 comments on commit 59240fd

Please sign in to comment.