Packages
A project that aims to fuse the concurrency models of OTP and Javascript to allow the careful user to write concurrent code that runs on both the otp backend and the gleam backend
Retired package: This is fundamentally broken, a new version will be published soon
Current section
4 Versions
Jump to
Current section
4 Versions
Compare versions
12
files changed
+89
additions
-74
deletions
| @@ -2,6 +2,8 @@ | |
| 2 2 | |
| 3 3 | A project that aims to fuse the concurrency models of OTP and Javascript to allow the careful user to write concurrent code that runs on both the otp backend and the gleam backend |
| 4 4 | |
| 5 | + Warning: this is still a work in progress and the API is subject to change |
| 6 | + |
| 5 7 | [](https://hex.pm/packages/fused) |
| 6 8 | [](https://hexdocs.pm/fused/) |
| @@ -1,5 +1,5 @@ | |
| 1 1 | name = "fused" |
| 2 | - version = "0.3.0" |
| 2 | + version = "0.4.0" |
| 3 3 | |
| 4 4 | # Fill out these fields if you intend to generate HTML documentation or publish |
| 5 5 | # your project to the Hex package manager. |
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"name">>, <<"fused"/utf8>>}. |
| 2 2 | {<<"app">>, <<"fused"/utf8>>}. |
| 3 | - {<<"version">>, <<"0.3.0"/utf8>>}. |
| 3 | + {<<"version">>, <<"0.4.0"/utf8>>}. |
| 4 4 | {<<"description">>, <<"A project that aims to fuse the concurrency models of OTP and Javascript to allow the careful user to write concurrent code that runs on both the otp backend and the gleam backend"/utf8>>}. |
| 5 5 | {<<"licenses">>, [<<"MIT"/utf8>>]}. |
| 6 6 | {<<"build_tools">>, [<<"gleam"/utf8>>]}. |
| @@ -8,8 +8,8 @@ | |
| 8 8 | {<<"Repository"/utf8>>, <<"https://github.com/aDifferentJT/fused"/utf8>>} |
| 9 9 | ]}. |
| 10 10 | {<<"requirements">>, [ |
| 11 | - {<<"interior"/utf8>>, [ |
| 12 | - {<<"app">>, <<"interior"/utf8>>}, |
| 11 | + {<<"gleam_javascript"/utf8>>, [ |
| 12 | + {<<"app">>, <<"gleam_javascript"/utf8>>}, |
| 13 13 | {<<"optional">>, false}, |
| 14 14 | {<<"requirement">>, <<">= 1.0.0 and < 2.0.0"/utf8>>} |
| 15 15 | ]}, |
| @@ -18,15 +18,15 @@ | |
| 18 18 | {<<"optional">>, false}, |
| 19 19 | {<<"requirement">>, <<">= 1.0.0 and < 2.0.0"/utf8>>} |
| 20 20 | ]}, |
| 21 | + {<<"interior"/utf8>>, [ |
| 22 | + {<<"app">>, <<"interior"/utf8>>}, |
| 23 | + {<<"optional">>, false}, |
| 24 | + {<<"requirement">>, <<">= 1.0.0 and < 2.0.0"/utf8>>} |
| 25 | + ]}, |
| 21 26 | {<<"gleam_erlang"/utf8>>, [ |
| 22 27 | {<<"app">>, <<"gleam_erlang"/utf8>>}, |
| 23 28 | {<<"optional">>, false}, |
| 24 29 | {<<"requirement">>, <<">= 1.3.0 and < 2.0.0"/utf8>>} |
| 25 | - ]}, |
| 26 | - {<<"gleam_javascript"/utf8>>, [ |
| 27 | - {<<"app">>, <<"gleam_javascript"/utf8>>}, |
| 28 | - {<<"optional">>, false}, |
| 29 | - {<<"requirement">>, <<">= 1.0.0 and < 2.0.0"/utf8>>} |
| 30 30 | ]} |
| 31 31 | ]}. |
| 32 32 | {<<"files">>, [ |
| @@ -1,5 +1,5 @@ | |
| 1 1 | {application, fused, [ |
| 2 | - {vsn, "0.3.0"}, |
| 2 | + {vsn, "0.4.0"}, |
| 3 3 | {applications, [gleam_erlang, |
| 4 4 | gleam_javascript, |
| 5 5 | gleam_stdlib, |
| @@ -3,29 +3,30 @@ import fused/promise.{type Promise} | |
| 3 3 | import gleam/option.{type Option, None, Some} |
| 4 4 | |
| 5 5 | pub fn start( |
| 6 | - self self: Pid, |
| 7 | - init init: fn(Pid) -> #(state, Selector(message), returning), |
| 8 | - update update: fn(Pid, state, message) -> Option(state), |
| 6 | + parent parent: Pid, |
| 7 | + init init: fn(Pid) -> Promise(#(state, Selector(message), returning)), |
| 8 | + update update: fn(Pid, state, message) -> Promise(Option(state)), |
| 9 9 | ) -> Promise(returning) { |
| 10 10 | let #(return_send, return_recv) = process.new() |
| 11 11 | { |
| 12 | - use self <- process.spawn(self:) |
| 13 | - let #(state, selector, return) = init(self) |
| 12 | + use self <- process.spawn(parent:) |
| 13 | + use #(state, selector, return) <- promise.await(init(self)) |
| 14 14 | process.send(return_send, return) |
| 15 | - run(selector:, self:, state:, update:) |
| 15 | + loop(selector:, self:, state:, update:) |
| 16 16 | } |
| 17 17 | process.recv(return_recv) |
| 18 18 | } |
| 19 19 | |
| 20 | - fn run( |
| 20 | + fn loop( |
| 21 21 | selector selector: Selector(message), |
| 22 22 | self self: Pid, |
| 23 23 | state state: state, |
| 24 | - update update: fn(Pid, state, message) -> Option(state), |
| 24 | + update update: fn(Pid, state, message) -> Promise(Option(state)), |
| 25 25 | ) -> Promise(Nil) { |
| 26 26 | use message <- promise.await(selector_recv(self:, from: selector)) |
| 27 | - case update(self, state, message) { |
| 28 | - Some(state) -> run(selector:, self:, state:, update:) |
| 27 | + use state <- promise.await(update(self, state, message)) |
| 28 | + case state { |
| 29 | + Some(state) -> loop(selector:, self:, state:, update:) |
| 29 30 | None -> promise.resolve(Nil) |
| 30 31 | } |
| 31 32 | } |
Loading more files…