Skip to content

Commit

Permalink
Update for Gleam v0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Nov 6, 2023
1 parent 08f637f commit 47a193a
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: erlef/setup-beam@v1.16.0
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: "25.1"
gleam-version: "0.30.4"
otp-version: "26.1"
gleam-version: "0.32.2"
rebar3-version: "3"
- run: gleam test
- run: gleam format --check src test
6 changes: 3 additions & 3 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version = "0.7.0"
licences = ["Apache-2.0"]
description = "Fault tolerant multicore Gleam programs with OTP"

gleam = ">= 0.30.0"
gleam = ">= 0.32.0"

repository = { type = "github", user = "gleam-lang", repo = "otp" }
links = [
Expand All @@ -12,8 +12,8 @@ links = [
]

[dependencies]
gleam_stdlib = "~> 0.19"
gleam_stdlib = "~> 0.32"
gleam_erlang = "~> 0.22"

[dev-dependencies]
gleeunit = "~> 0.5"
gleeunit = "~> 1.0"
10 changes: 5 additions & 5 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_erlang", version = "0.22.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "367D8B41A7A86809928ED1E7E55BFD0D46D7C4CF473440190F324AFA347109B4" },
{ name = "gleam_stdlib", version = "0.30.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "8D8BF3790AA31176B1E1C0B517DD74C86DA8235CF3389EA02043EE4FD82AE3DC" },
{ name = "gleeunit", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "1397E5C4AC4108769EE979939AC39BF7870659C5AFB714630DEEEE16B8272AD5" },
{ name = "gleam_erlang", version = "0.23.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DA7A8E5540948DE10EB01B530869F8FF2FF6CAD8CFDA87626CE6EF63EBBF87CB" },
{ name = "gleam_stdlib", version = "0.32.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "07D64C26D014CF570F8ACADCE602761EA2E74C842D26F2FD49B0D61973D9966F" },
{ name = "gleeunit", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D3682ED8C5F9CAE1C928F2506DE91625588CC752495988CBE0F5653A42A6F334" },
]

[requirements]
gleam_erlang = { version = "~> 0.22" }
gleam_stdlib = { version = "~> 0.19" }
gleeunit = { version = "~> 0.5" }
gleam_stdlib = { version = "~> 0.32" }
gleeunit = { version = "~> 1.0" }
14 changes: 8 additions & 6 deletions src/gleam/otp/actor.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,18 @@
//// }
//// ```

import gleam/erlang/process.{Abnormal, ExitReason, Pid, Selector, Subject}
import gleam/erlang/charlist.{Charlist}
import gleam/erlang/process.{
type ExitReason, type Pid, type Selector, type Subject, Abnormal,
}
import gleam/erlang/charlist.{type Charlist}
import gleam/otp/system.{
DebugState, GetState, GetStatus, Mode, Resume, Running, StatusInfo, Suspend,
Suspended, SystemMessage,
type DebugState, type Mode, type StatusInfo, type SystemMessage, GetState,
GetStatus, Resume, Running, StatusInfo, Suspend, Suspended,
}
import gleam/string
import gleam/dynamic.{Dynamic}
import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom
import gleam/option.{None, Option, Some}
import gleam/option.{type Option, None, Some}

type Message(message) {
/// A regular message excepted by the process
Expand Down
10 changes: 5 additions & 5 deletions src/gleam/otp/supervisor.gleam
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// TODO: specify amount of time permitted for shut-down
import gleam/result
import gleam/string
import gleam/option.{None, Option, Some}
import gleam/erlang/process.{Pid, Subject}
import gleam/otp/actor.{StartError}
import gleam/otp/intensity_tracker.{IntensityTracker}
import gleam/erlang/node.{Node}
import gleam/option.{type Option, None, Some}
import gleam/erlang/process.{type Pid, type Subject}
import gleam/otp/actor.{type StartError}
import gleam/otp/intensity_tracker.{type IntensityTracker}
import gleam/erlang/node.{type Node}

/// This data structure holds all the values required by the `start_spec`
/// function in order to create an supervisor.
Expand Down
6 changes: 3 additions & 3 deletions src/gleam/otp/system.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleam/dynamic.{Dynamic}
import gleam/erlang/atom.{Atom}
import gleam/erlang/process.{Pid}
import gleam/dynamic.{type Dynamic}
import gleam/erlang/atom.{type Atom}
import gleam/erlang/process.{type Pid}

pub type Mode {
Running
Expand Down
4 changes: 2 additions & 2 deletions src/gleam/otp/task.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
////

// TODO: await_many
import gleam/erlang/process.{Pid, ProcessMonitor, Selector}
import gleam/dynamic.{Dynamic}
import gleam/erlang/process.{type Pid, type ProcessMonitor, type Selector}
import gleam/dynamic.{type Dynamic}

pub opaque type Task(value) {
Task(
Expand Down
27 changes: 27 additions & 0 deletions src/gleam_otp.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import gleam/io
import gleam/int
import gleam/list
import gleam/otp/task
import gleam/erlang/process.{type Pid}

@external(erlang, "gleam_otp_test_external", "get_message_queue_length")
fn get_message_queue_length(pid pid: Pid) -> Int

fn spawn_task(i) {
task.async(fn() {
case i % 500 == 0 {
True -> io.println("Hello from " <> int.to_string(i))
False -> Nil
}
})
}

pub fn main() {
io.debug(get_message_queue_length(process.self()))

list.range(0, 1_000_000)
|> list.map(spawn_task)
|> list.each(task.await_forever)

io.debug(get_message_queue_length(process.self()))
}
2 changes: 1 addition & 1 deletion test/gleam/otp/actor_documentation_example_test.gleam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//// If you update this file be sure to update the documentation in the actor
//// module which includes a copy of this.

import gleam/erlang/process.{Subject}
import gleam/erlang/process.{type Subject}
import gleam/otp/actor

pub fn example_test() {
Expand Down
6 changes: 3 additions & 3 deletions test/gleam/otp/actor_test.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import gleam/otp/actor
import gleam/erlang/process.{Pid, Subject}
import gleam/erlang/atom.{Atom}
import gleam/erlang/process.{type Pid, type Subject}
import gleam/erlang/atom.{type Atom}
import gleam/otp/system
import gleam/dynamic.{Dynamic}
import gleam/dynamic.{type Dynamic}
import gleam/int
import gleam/result
import gleam/function
Expand Down
2 changes: 1 addition & 1 deletion test/gleam/otp/task_test.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gleeunit/should
import gleam/otp/task.{Timeout}
import gleam/erlang/process.{Pid}
import gleam/erlang/process.{type Pid}

@external(erlang, "gleam_otp_test_external", "flush")
fn flush() -> Nil
Expand Down
4 changes: 2 additions & 2 deletions test/gleam/periodic_actor.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//// An example of an actor that concurrently does something every X amount of
//// time (or when it is sent a message by another process).

import gleam/erlang/process.{Subject}
import gleam/otp/actor.{Ready, Spec, StartError}
import gleam/erlang/process.{type Subject}
import gleam/otp/actor.{type StartError, Ready, Spec}
import gleam/io

pub fn periodic_actor(
Expand Down

0 comments on commit 47a193a

Please sign in to comment.