diff --git a/drift_actor/CHANGELOG.md b/drift_actor/CHANGELOG.md index c493e4a..0b5c07b 100644 --- a/drift_actor/CHANGELOG.md +++ b/drift_actor/CHANGELOG.md @@ -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. @@ -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 \ No newline at end of file +[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 \ No newline at end of file diff --git a/drift_js/CHANGELOG b/drift_js/CHANGELOG new file mode 100644 index 0000000..b0fa781 --- /dev/null +++ b/drift_js/CHANGELOG @@ -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 \ No newline at end of file diff --git a/drift_js/gleam.toml b/drift_js/gleam.toml index fdd0a78..0952b58 100644 --- a/drift_js/gleam.toml +++ b/drift_js/gleam.toml @@ -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] diff --git a/drift_js/src/drift/js/channel.gleam b/drift_js/src/drift/js/channel.gleam index bcdeba8..17dd507 100644 --- a/drift_js/src/drift/js/channel.gleam +++ b/drift_js/src/drift/js/channel.gleam @@ -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) }) @@ -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 diff --git a/drift_js/src/drift_channel.mjs b/drift_js/src/drift_channel.mjs index d173ced..6ade43e 100644 --- a/drift_js/src/drift_channel.mjs +++ b/drift_js/src/drift_channel.mjs @@ -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) { @@ -62,8 +62,10 @@ export class Channel { } } - cancel_receive() { - this.#handler = null; + cancel_receive(callback) { + if (this.#handler === callback) { + this.#handler = null; + } } send(message) { diff --git a/drift_js/test/drift/js/channel_test.gleam b/drift_js/test/drift/js/channel_test.gleam index c80cc87..7d2fbf3 100644 --- a/drift_js/test/drift/js/channel_test.gleam +++ b/drift_js/test/drift/js/channel_test.gleam @@ -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() {