Skip to content

Commit a71dc4e

Browse files
committed
v0.30.0
1 parent 4a22be1 commit a71dc4e

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.30.0 - 2024-11-11
4+
5+
- The `gleam/erlang/process` module gains the `deselecting` function.
6+
37
## v0.29.0 - 2024-11-10
48

59
- The `gleam/erlang/process` module gains the `call_forever` and

gleam.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "gleam_erlang"
22

3-
version = "0.29.0"
3+
version = "0.30.0"
44
licences = ["Apache-2.0"]
55
description = "A Gleam library for working with Erlang"
66

src/gleam/erlang/process.gleam

+14-1
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ pub fn selecting_trapped_exits(
256256
@external(erlang, "gleam_erlang_ffi", "flush_messages")
257257
pub fn flush_messages() -> Nil
258258

259-
/// Add a new `Subject` to the `Selector` to that it's messages can be received.
259+
/// Add a new `Subject` to the `Selector` so that its messages can be selected
260+
/// from the receiver process inbox.
260261
///
261262
/// The `mapping` function provided with the `Subject` can be used to convert
262263
/// the type of messages received using this `Subject`. This is useful for when
263264
/// you wish to add multiple `Subject`s to a `Selector` when they have differing
264265
/// message types. If you do not wish to transform the incoming messages in any
265266
/// way then the `identity` function can be given.
266267
///
268+
/// See `deselecting` to remove a subject from a selector.
269+
///
267270
pub fn selecting(
268271
selector: Selector(payload),
269272
for subject: Subject(message),
@@ -273,6 +276,16 @@ pub fn selecting(
273276
insert_selector_handler(selector, #(subject.tag, 2), handler)
274277
}
275278

279+
/// Remove a new `Subject` from the `Selector` so that its messages will not be
280+
/// selected from the receiver process inbox.
281+
///
282+
pub fn deselecting(
283+
selector: Selector(payload),
284+
for subject: Subject(message),
285+
) -> Selector(payload) {
286+
remove_selector_handler(selector, #(subject.tag, 2))
287+
}
288+
276289
/// Add a handler to a selector for 2 element tuple messages with a given tag
277290
/// element in the first position.
278291
///

test/gleam/erlang/process_test.gleam

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import gleam/float
55
import gleam/function
66
import gleam/int
77
import gleam/option.{Some}
8+
import gleeunit/should
89

910
pub fn self_test() {
1011
let subject = process.new_subject()
@@ -613,3 +614,24 @@ pub fn pid_from_dynamic_test() {
613614
|> dynamic.from
614615
|> process.pid_from_dynamic
615616
}
617+
618+
pub fn deselecting_test() {
619+
let subject1 = process.new_subject()
620+
let subject2 = process.new_subject()
621+
let selector0 = process.new_selector()
622+
let selector1 = selector0 |> process.selecting(subject1, function.identity)
623+
let selector2 = selector1 |> process.selecting(subject2, function.identity)
624+
625+
selector2
626+
|> process.deselecting(subject2)
627+
|> should.equal(selector1)
628+
629+
selector1
630+
|> process.deselecting(subject1)
631+
|> should.equal(selector0)
632+
633+
selector2
634+
|> process.deselecting(subject1)
635+
|> process.deselecting(subject2)
636+
|> should.equal(selector0)
637+
}

0 commit comments

Comments
 (0)