diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/README.md | 1 | ||||
| -rw-r--r-- | docs/channels.md | 177 | ||||
| -rw-r--r-- | docs/optionals.md | 6 | ||||
| -rw-r--r-- | docs/threads.md | 2 |
4 files changed, 4 insertions, 182 deletions
diff --git a/docs/README.md b/docs/README.md index 960ed4af..c1e6cf88 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,7 +21,6 @@ Information about Tomo's built-in types can be found here: - [Arrays](arrays.md) - [Booleans](booleans.md) - [Bytes](bytes.md) -- [Channels](channels.md) - [Moment](moments.md) - [Enums](enums.md) - [Floating point numbers](nums.md) diff --git a/docs/channels.md b/docs/channels.md deleted file mode 100644 index ab61a82a..00000000 --- a/docs/channels.md +++ /dev/null @@ -1,177 +0,0 @@ -# Channels - -Channels are a thread-safe message queue for communicating between threads, -although they can also be used as a general-purpose queue. - -## Syntax - -The syntax to create a channel is `|:T|`, where `T` is the type that will be -passed through the channel. You can also specify a maximum size for the -channel, which will cause giving to block until the recipient has gotten from -the channel if the maximum size is reached. - -```tomo -channel := |:Int| -channel:give(10) -channel:give(20) ->> channel:get() -= 10 ->> channel:get() -= 20 - -small_channel := |:Int; max_size=5| -``` - -## Channel Methods - -### `give` - -**Description:** -Adds an item to the channel. - -**Signature:** -```tomo -func give(channel:|T|, item: T, front: Bool = no -> Void) -``` - -**Parameters:** - -- `channel`: The channel to which the item will be added. -- `item`: The item to add to the channel. -- `front`: Whether to put the item at the front of the channel (as opposed to the back). - -**Returns:** -Nothing. - -**Example:** -```tomo ->> channel:give("Hello") -``` - ---- - -### `give_all` - -**Description:** -Adds multiple items to the channel. - -**Signature:** -```tomo -func give_all(channel:|T|, items: [T], front: Bool = no -> Void) -``` - -**Parameters:** - -- `channel`: The channel to which the items will be added. -- `items`: The array of items to add to the channel. -- `front`: Whether to put the item at the front of the channel (as opposed to the back). - -**Returns:** -Nothing. - -**Example:** -```tomo ->> channel:give_all([1, 2, 3]) -``` - ---- - -### `get` - -**Description:** -Removes and returns an item from the channel. If the channel is empty, it waits until an item is available. - -**Signature:** -```tomo -func get(channel:|T|, front: Bool = yes -> T) -``` - -**Parameters:** - -- `channel`: The channel from which to remove an item. -- `front`: Whether to put the item at the front of the channel (as opposed to the back). - -**Returns:** -The item removed from the channel. - -**Example:** -```tomo ->> channel:peek() -= "Hello" -``` - ---- - -### `peek` - -**Description:** -Returns the next item that will come out of the channel, but without removing -it. If the channel is empty, it waits until an item is available. - -**Signature:** -```tomo -func peek(channel:|T|, front: Bool = yes -> T) -``` - -**Parameters:** - -- `channel`: The channel from which to remove an item. -- `front`: Whether to put the item at the front of the channel (as opposed to the back). - -**Returns:** -The item removed from the channel. - -**Example:** -```tomo ->> channel:get() -= "Hello" -``` - ---- - -### `clear` - -**Description:** -Removes all items from the channel. - -**Signature:** -```tomo -func clear(channel:|T| -> Void) -``` - -**Parameters:** - -- `channel`: The mutable reference to the channel. - -**Returns:** -Nothing. - -**Example:** -```tomo ->> channel:clear() -``` - ---- - -### `view` - -**Description:** -Returns a list of all items currently in the channel without removing them. - -**Signature:** -```tomo -func channel:view(->[T]) -``` - -**Parameters:** - -- `channel`: The channel to view. - -**Returns:** -An array of items currently in the channel. - -**Example:** -```tomo ->> channel:view() -= [1, 2, 3] -``` diff --git a/docs/optionals.md b/docs/optionals.md index 56b7ba16..84f886b7 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -127,9 +127,9 @@ for line in lines: ## Implementation Notes The implementation of optional types is highly efficient and has no memory -overhead for pointers, collection types (arrays, sets, tables, channels), -booleans, texts, enums, nums, or integers (`Int` type only). This is done by -using carefully chosen values, such as `0` for pointers, `2` for booleans, or a +overhead for pointers, collection types (arrays, sets, tables), booleans, +texts, enums, nums, or integers (`Int` type only). This is done by using +carefully chosen values, such as `0` for pointers, `2` for booleans, or a negative length for arrays. However, for fixed-size integers (`Int64`, `Int32`, `Int16`, and `Int8`), bytes, and structs, an additional byte is required for out-of-band information about whether the value is none or not. diff --git a/docs/threads.md b/docs/threads.md index 68fdf7d7..44f5967e 100644 --- a/docs/threads.md +++ b/docs/threads.md @@ -2,7 +2,7 @@ Tomo supports POSIX threads (pthreads) through the `Thread` type. The recommended practice is to have each thread interact with other threads only -through thread-safe Channels with no other shared data. +through mutex-guarded datastructures. ## Thread Methods |
