Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions drift_actor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [2.0.0] - 2025-07-20

### Changed
- Revamp the poorly designed API for starting actors.
Now supports named subjects, is safer, and should support future extensions better.
Expand All @@ -16,5 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release with basic functionality.

[Unreleased]: https://github.com/sbergen/spoke/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/sbergen/spoke/releases/tag/v1.0.0
[Unreleased]: https://github.com/sbergen/drift/compare/drift_actor-v2.0.0...HEAD
[2.0.0]: https://github.com/sbergen/drift/releases/tag/drift_actor-v2.0.0
[1.0.0]: https://github.com/sbergen/drift/releases/tag/v1.0.0
23 changes: 23 additions & 0 deletions drift_js/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## [1.0.1] - 2025-17-20

### Fixed
- Fix bug in `channel`, where a previous `receive` (with a timeout) could
prevent later `receive` calls from functioning properly.

## [1.0.0] - 2025-07-19

### Added
- Initial release with basic functionality.

[Unreleased]: https://github.com/sbergen/drift/compare/drift_js-v1.0.1...HEAD
[1.0.1]: https://github.com/sbergen/drift/releases/tag/drift_js-v1.0.1
[1.0.0]: https://github.com/sbergen/drift/releases/tag/v1.0.0
4 changes: 2 additions & 2 deletions drift_js/gleam.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = "drift_js"
version = "1.0.0"
version = "1.0.1"
target = "javascript"

description = "Run drift steppers on JavaScript targets."
licences = ["Apache-2.0"]
repository = { type = "github", user = "sbergen", repo = "drift", path = "drift_js" }
repository = { type = "github", user = "sbergen", repo = "drift", path = "drift_js", tag-prefix = "drift_js-" }
internal_modules = ["drift/js/internal/*"]

[dependencies]
Expand Down
12 changes: 7 additions & 5 deletions drift_js/src/drift/js/channel.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ pub fn receive(
from channel: Channel(a),
within timeout: Int,
) -> Promise(Result(a, ReceiveError)) {
let receive =
receive_forever(channel)
|> promise.map(result.replace_error(_, AlreadyReceiving))
let #(promise, resolve) = promise.start()
let receive = case channel_receive(channel, resolve) {
Ok(_) -> promise.map(promise, Ok)
Error(_) -> promise.resolve(Error(AlreadyReceiving))
}

let timeout =
promise.wait(timeout)
|> promise.map(fn(_) {
cancel_receive(channel)
cancel_receive(channel, resolve)
Error(ReceiveTimeout)
})

Expand All @@ -74,4 +76,4 @@ fn channel_receive(
) -> Result(Bool, Nil)

@external(javascript, "../../drift_channel.mjs", "cancel_receive")
fn cancel_receive(channel: Channel(a)) -> Nil
fn cancel_receive(channel: Channel(a), callback: fn(a) -> Nil) -> Nil
10 changes: 6 additions & 4 deletions drift_js/src/drift_channel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function receive(channel, callback) {
}
}

export function cancel_receive(channel) {
channel.cancel_receive()
export function cancel_receive(channel, callback) {
channel.cancel_receive(callback);
}

export function try_receive(channel) {
Expand Down Expand Up @@ -62,8 +62,10 @@ export class Channel {
}
}

cancel_receive() {
this.#handler = null;
cancel_receive(callback) {
if (this.#handler === callback) {
this.#handler = null;
}
}

send(message) {
Expand Down
9 changes: 9 additions & 0 deletions drift_js/test/drift/js/channel_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ pub fn receive_timeout_test() {
channel.send(channel, 42)
use result <- promise.map(channel.receive(channel, 10))
assert result == Ok(42)

// Can receive after previous timeout expires
let pending = channel.receive(channel, 20)
use _ <- promise.await(promise.wait(10))
channel.send(channel, 43)

use result <- promise.map(pending)
assert result == Ok(43)
Nil
}

pub fn double_receive_test() {
Expand Down