This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
383 additions
and
413 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,5 +1,5 @@ | ||
{ | ||
"emitLegacyScripts": true, | ||
"emitLegacyScripts": false, | ||
"name": "net", | ||
"tree": { | ||
"$className": "DataModel", | ||
|
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Async | ||
|
||
A client-sided async. | ||
|
||
## Properties | ||
|
||
--- | ||
|
||
### `Reliable` | ||
|
||
Whether or not the async uses a reliable remote event. | ||
|
||
- **boolean** | ||
|
||
## Methods | ||
|
||
--- | ||
|
||
### `Request` | ||
|
||
Requests data the server, equivalent to [RemoteFunction:InvokeServer](https://create.roblox.com/docs/reference/engine/classes/RemoteFunction#InvokeServer). Returns a Future. | ||
|
||
**Parameters** | ||
|
||
- **data:** `...any`<br> | ||
The data to request the server with | ||
|
||
**Returns** | ||
|
||
- **...any** |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Async | ||
|
||
A server-sided async. | ||
|
||
## Properties | ||
|
||
--- | ||
|
||
### `Reliable` | ||
|
||
Whether or not the async uses a reliable remote event. | ||
|
||
- **boolean** | ||
|
||
## Methods | ||
|
||
--- | ||
|
||
### `OnRequest` | ||
|
||
Recieves a request from the client, and runs the callback function which returns some data. Equivalent to [RemoteFunction.OnServerInvoke](https://create.roblox.com/docs/reference/engine/classes/RemoteFunction#OnServerInvoke). | ||
|
||
**Parameters** | ||
|
||
- **callback:** `(sender: Player, ...: any) -> (any, ...any)`<br> | ||
The callback function to run on requesting, must return at least 1 value | ||
|
||
**Returns** | ||
|
||
- **void** | ||
|
||
--- | ||
|
||
### `SetMiddleware` | ||
|
||
Allows you to set middleware that runs at specific points in time. | ||
|
||
**Parameters** | ||
|
||
- **middleware** `{ [MiddlewareType]: (...any) -> () }`<br> | ||
A table of middleware for the event. | ||
|
||
**Returns** | ||
|
||
- **void** |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Interface | ||
|
||
References the server event and function constructors | ||
|
||
## Functions | ||
|
||
--- | ||
|
||
### `Event` | ||
|
||
Creates a new event | ||
|
||
**Parameters** | ||
|
||
- **name:** `string`\ | ||
The name of the event to reference or create | ||
|
||
- **reliable:** `boolean`\ | ||
Whether the event should be reliable or not. Defaults to true | ||
|
||
- **types:** `{ string }`\ | ||
Type validation params to be applied at `Listen` | ||
|
||
**Returns** | ||
|
||
- [**Event**](./event) | ||
|
||
--- | ||
|
||
### `Async` | ||
|
||
Creates a new async | ||
|
||
**Parameters** | ||
|
||
- **name:** `string`\ | ||
The name of the async to reference or create | ||
|
||
- **reliable:** `boolean`\ | ||
Whether the async should be reliable or not. Defaults to true\ | ||
*This currently has no effect on asyncs* | ||
|
||
- **types:** `{ string }`\ | ||
Type validation params to be applied at `OnRequest` | ||
|
||
**Returns** | ||
|
||
- [**Async**](./async) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Asyncs | ||
|
||
Asyncs are similar to how RemoteFunctions work and also act as a better way to perform tasks where the server returns data back to the client in a call. | ||
|
||
## Requesting | ||
|
||
Requesting is done on the client. Calling this method will yield the thread until the value is resolved. | ||
|
||
```luau | ||
local Net = require(Packages.net).Client | ||
local MyAsync = Net.Async("MyAsync") | ||
local Response = MyAsync:Request("Hi") | ||
print(Response) -- Output: Goodbye | ||
``` | ||
|
||
## Listening To Request | ||
|
||
When listening to a request you must return a value. This is what happens on the server, and if you don't return a value it defeats the purpose of using a async. Use an event instead for this. | ||
|
||
```luau | ||
local Net = require(Packages.net).Client | ||
local MyAsync = Net.Async("MyAsync") | ||
MyAsync:OnRequest(function(sender, data) | ||
if data == "Hi" then | ||
return "Goodbye" | ||
end | ||
return "Huh?" | ||
end) | ||
``` |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Middleware | ||
|
||
The middleware feature allows you to run functions before or after something happens. For example, the `Throttle` middleware runs before the internal `Listen` code is ran and will throttle the event with your code. | ||
|
||
## Usage | ||
|
||
There are 2 different types of middleware. These are `Throttle` and `Dropped`. Throttle runs before `Listen` or `OnRequest`, and `Dropped` runs when the packet is dropped due to invalid types or NaN. | ||
|
||
```luau | ||
local Net = require(Packages.net).Server | ||
local MyEvent = Net.Event("MyEvent") | ||
MyEvent:SetMiddleware({ | ||
Throttle = function() | ||
if math.random(1, 2) == 1 then | ||
print("I randomly decided to throttle.") | ||
return false -- Returning false indicates that the event/async should throttle | ||
end | ||
return true | ||
end, | ||
Dropped = function(sender) | ||
print(sender.Name, "sent the incorrect value from the client!") | ||
end, | ||
}) | ||
MyEvent:Listen(function() | ||
print("Might print depending on the throttle middleware.") | ||
end) | ||
``` | ||
|
||
`Dropped` middleware is explained further in the [type validation article](type-validation.md). |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.