Skip to content

Commit

Permalink
v0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Dec 8, 2024
1 parent 1c8c9eb commit d72aeb3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 86 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.15.0 - 2024-12-08

- The deprecated `try_await_forever` function in the `gleam/otp/task` module has
been removed.

## v0.14.1 - 2024-11-15

- Fixed a bug where the `significant` parameter would not be passed to the
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "gleam_otp"
version = "0.14.1"
version = "0.15.0"
licences = ["Apache-2.0"]
description = "Fault tolerant multicore Gleam programs with OTP"

Expand Down
4 changes: 2 additions & 2 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_erlang", version = "0.28.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "BE551521F708DCE5CB954AFBBDF08519C1C44986521FD40753608825F48FFA9E" },
{ name = "gleam_stdlib", version = "0.41.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1B2F80CB1B66B027E3198A2FF71EF3F2F31DF89ED97AD606F25FD387A4C3C1EF" },
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
{ name = "gleam_stdlib", version = "0.45.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "206FCE1A76974AECFC55AEBCD0217D59EDE4E408C016E2CFCCC8FF51278F186E" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
{ name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" },
]
Expand Down
12 changes: 0 additions & 12 deletions src/gleam/otp/task.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ pub fn pid(task: Task(value)) -> Pid {
task.pid
}

@deprecated("Use await_forever")
pub fn try_await_forever(task: Task(value)) -> Result(value, AwaitError) {
assert_owner(task)
let selector =
process.new_selector()
|> process.selecting(task.subject, function.identity)
case process.select_forever(selector) {
// The task process has sent back a value
x -> Ok(x)
}
}

/// Wait endlessly for the value computed by a task.
///
/// Be Careful! Like `try_await_forever`, this function does not return until
Expand Down
72 changes: 1 addition & 71 deletions test/gleam/otp/task_test.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import gleam/dynamic
import gleam/erlang/atom
import gleam/erlang/process.{type Pid}
import gleam/function
import gleam/io
import gleam/otp/task.{Exit, Timeout}
import gleam/string
import gleam/otp/task.{Timeout}
import gleeunit/should

@external(erlang, "gleam_otp_test_external", "flush")
Expand Down Expand Up @@ -61,72 +57,6 @@ pub fn async_await_unmonitor_test() {
|> should.equal(0)
}

pub fn async_await_forever_test() {
// Spawn 3 tasks, performing 45ms work collectively
let t1 = task.async(work(1))
let t2 = task.async(work(2))
let t3 = task.async(work(3))

// Assert they run concurrently (not caring how long they take)
task.try_await_forever(t1)
|> should.equal(Ok(1))
task.try_await_forever(t2)
|> should.equal(Ok(2))
task.try_await_forever(t3)
|> should.equal(Ok(3))

// Spawn 3 more tasks, performing 45ms work collectively
let t4 = task.async(work(4))
let t5 = task.async(work(5))
let t6 = task.async(work(6))

// Assert they run concurrently (not caring how long they take)
task.await_forever(t4)
|> should.equal(4)
task.await_forever(t5)
|> should.equal(5)
task.await_forever(t6)
|> should.equal(6)
}

pub fn async_await_forever_unmonitor_test() {
// Start with an empty mailbox
flush()

// Perform an asynchronous task
// and monitor it until it's done
let _result =
task.async(work(1))
|> task.try_await_forever

// Mailbox should be empty;
// no "DOWN" message should have been sent
process.self()
|> get_message_queue_length
|> should.equal(0)
}

pub fn try_await2_test() {
// Start with an empty mailbox
flush()

let work = fn(x) {
fn() {
sleep(5)
x
}
}

let task1 = task.async(work(1))
let task2 = task.async(work(2))

task.try_await2(task1, task2, 8)
|> should.equal(#(Ok(1), Ok(2)))

// We want to make sure timers don't leak!
assert_no_leftover_messages()
}

fn assert_no_leftover_messages() -> Nil {
let selector =
process.new_selector()
Expand Down

0 comments on commit d72aeb3

Please sign in to comment.