Skip to content

Commit a177bc6

Browse files
committed
remove references to Task
1 parent c232429 commit a177bc6

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ A webserver [platform](https://github.com/roc-lang/roc/wiki/Roc-concepts-explain
1717

1818
## Example
1919

20-
Run this example server with `$ roc helloweb.roc` (on linux, add `--linker=legacy`) and go to `http://localhost:8000` in your browser. You can change the port (8000) and the host (localhost) by setting the environment variables ROC_BASIC_WEBSERVER_PORT and ROC_BASIC_WEBSERVER_HOST.
20+
Run this example server with `$ roc hello-web.roc` (on linux, add `--linker=legacy`) and go to `http://localhost:8000` in your browser. You can change the port (8000) and the host (localhost) by setting the environment variables ROC_BASIC_WEBSERVER_PORT and ROC_BASIC_WEBSERVER_HOST.
2121

2222
```roc
23-
app [Model, server] { pf: platform "https://github.com/roc-lang/basic-webserver/releases/download/0.10.0/BgDDIykwcg51W8HA58FE_BjdzgXVk--ucv6pVb_Adik.tar.br" }
23+
app [Model, init!, respond!] { pf: platform "../platform/main.roc" }
2424
2525
import pf.Stdout
2626
import pf.Http exposing [Request, Response]
@@ -31,19 +31,22 @@ Model : {}
3131
3232
# With `init` you can set up a database connection once at server startup,
3333
# generate css by running `tailwindcss`,...
34-
# In this case we don't have anything to initialize, so it is just `Task.ok {}`.
34+
# In this case we don't have anything to initialize, so it is just `Ok {}`.
35+
init! : {} => Result Model []
36+
init! = \{} -> Ok {}
3537
36-
server = { init: Task.ok {}, respond }
37-
38-
respond : Request, Model -> Task Response [ServerErr Str]_
39-
respond = \req, _ ->
38+
respond! : Request, Model => Result Response [ServerErr Str]_
39+
respond! = \req, _ ->
4040
# Log request datetime, method and url
41-
datetime = Utc.now! |> Utc.toIso8601Str
42-
43-
Stdout.line! "$(datetime) $(Http.methodToStr req.method) $(req.url)"
41+
datetime = Utc.to_iso_8601 (Utc.now! {})
4442
45-
Task.ok { status: 200, headers: [], body: Str.toUtf8 "<b>Hello, web!</b></br>" }
43+
try Stdout.line! "$(datetime) $(Inspect.toStr req.method) $(req.uri)"
4644
45+
Ok {
46+
status: 200,
47+
headers: [],
48+
body: Str.toUtf8 "<b>Hello from server</b></br>",
49+
}
4750
```
4851

4952

platform/Env.roc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var! = \name ->
5252
## Reads the given environment variable and attempts to decode it.
5353
##
5454
## The type being decoded into will be determined by type inference. For example,
55-
## if this ends up being used like a `Task U16 _` then the environment variable
55+
## if this ends up being used like a `Result U16 _` then the environment variable
5656
## will be decoded as a string representation of a `U16`. Trying to decode into
5757
## any other type will fail with a `DecodeErr`.
5858
##
@@ -65,8 +65,8 @@ var! = \name ->
6565
##
6666
## ```
6767
## # Reads "NUM_THINGS" and decodes into a U16
68-
## getU16Var : Str -> Task U16 [VarNotFound, DecodeErr DecodeError] [Read [Env]]
69-
## getU16Var = \var -> Env.decode! var
68+
## get_u16_var! : Str => Result U16 [VarNotFound, DecodeErr DecodeError] [Read [Env]]
69+
## get_u16_var! = \var -> Env.decode! var
7070
## ```
7171
##
7272
## If `NUM_THINGS=123` then `getU16Var` succeeds with the value of `123u16`.
@@ -108,10 +108,9 @@ dict! = \{} ->
108108
# ##
109109
# ## If any key or value contains invalid Unicode, the [Unicode replacement character](https://unicode.org/glossary/#replacement_character)
110110
# ## (`�`) will be used in place of any parts of keys or values that are invalid Unicode.
111-
# walk : state, (state, Str, Str -> state) -> Task state [NonUnicodeEnv state] [Read [Env]]
112-
# walk = \state, walker ->
113-
# Effect.envWalk state walker
114-
# |> InternalTask.fromEffect
111+
# walk! : state, (state, Str, Str -> state) => Result state [NonUnicodeEnv state] [Read [Env]]
112+
# walk! = \state, walker ->
113+
# Host.env_walk! state walker
115114
# TODO could potentially offer something like walkNonUnicode which takes (state, Result Str Str, Result Str Str) so it
116115
# tells you when there's invalid Unicode. This is both faster than (and would give you more accurate info than)
117116
# using regular `walk` and searching for the presence of the replacement character in the resulting
@@ -123,7 +122,7 @@ dict! = \{} ->
123122
# decode all the required vars only, and then decode the optional ones separately some other way.
124123
# Alternatively, it could make sense to have some sort of tag union convention here, e.g.
125124
# if decoding into a tag union of [Present val, Missing], then it knows what to do.
126-
# decodeAll : Task val [] [EnvDecodingFailed Str] [Env] where val implements Decoding
125+
# decode_all : Result val [] [EnvDecodingFailed Str] [Env] where val implements Decoding
127126

128127
ARCH : [X86, X64, ARM, AARCH64, OTHER Str]
129128
OS : [LINUX, MACOS, WINDOWS, OTHER Str]

platform/Path.roc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ display = \path ->
174174
Err _ -> ""
175175

176176
## Returns true if the path exists on disk and is pointing at a directory.
177-
## Returns `Task.ok false` if the path exists and it is not a directory. If the path does not exist,
178-
## this function will return `Task.err PathErr PathDoesNotExist`.
177+
## Returns `Ok false` if the path exists and it is not a directory. If the path does not exist,
178+
## this function will return `Err (PathErr PathDoesNotExist)`.
179179
##
180180
## This uses [rust's std::path::is_dir](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_dir).
181181
##
@@ -186,8 +186,8 @@ is_dir! = \path ->
186186
Ok (res == IsDir)
187187

188188
## Returns true if the path exists on disk and is pointing at a regular file.
189-
## Returns `Task.ok false` if the path exists and it is not a file. If the path does not exist,
190-
## this function will return `Task.err PathErr PathDoesNotExist`.
189+
## Returns `Ok false` if the path exists and it is not a file. If the path does not exist,
190+
## this function will return `Err (PathErr PathDoesNotExist)`.
191191
##
192192
## This uses [rust's std::path::is_file](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_file).
193193
##
@@ -198,8 +198,8 @@ is_file! = \path ->
198198
Ok (res == IsFile)
199199

200200
## Returns true if the path exists on disk and is pointing at a symbolic link.
201-
## Returns `Task.ok false` if the path exists and it is not a symbolic link. If the path does not exist,
202-
## this function will return `Task.err PathErr PathDoesNotExist`.
201+
## Returns `Ok false` if the path exists and it is not a symbolic link. If the path does not exist,
202+
## this function will return `Err (PathErr PathDoesNotExist)`.
203203
##
204204
## This uses [rust's std::path::is_symlink](https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink).
205205
##

platform/Tcp.roc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ parse_connect_err = \err ->
4444
"ErrorKind::Unsupported" -> Unsupported
4545
other -> Unrecognized other
4646

47-
## Represents errors that can occur when performing a [Task] with a [Stream].
47+
## Represents errors that can occur when performing an effect with a [Stream].
4848
StreamErr : [
4949
StreamNotFound,
5050
PermissionDenied,

platform/main.roc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ init_for_host! = \_ ->
4444
Program exited with error:
4545
$(Inspect.toStr err)
4646
47-
Tip: If you do not want to exit on this error, use `Task.mapErr` to handle the error.
48-
Docs for `Task.mapErr`: <https://roc-lang.github.io/basic-webserver/Task/#mapErr>
47+
Tip: If you do not want to exit on this error, use `Result.mapErr` to handle the error.
48+
Docs for `Result.mapErr`: <https://www.roc-lang.org/builtins/Result#mapErr>
4949
"""
5050
Err 1
5151

@@ -71,8 +71,8 @@ respond_for_host! = \request, boxed_model ->
7171
Server error:
7272
$(Inspect.toStr err)
7373
74-
Tip: If you do not want to see this error, use `Task.mapErr` to handle the error.
75-
Docs for `Task.mapErr`: <https://roc-lang.github.io/basic-webserver/Task/#mapErr>
74+
Tip: If you do not want to see this error, use `Result.mapErr` to handle the error.
75+
Docs for `Result.mapErr`: <https://www.roc-lang.org/builtins/Result#mapErr>
7676
"""
7777

7878
# returns a http server error response

0 commit comments

Comments
 (0)