this repo has no description

Update to v1 versions of gleam_erlang and gleam_otp

Signed-off-by: Naomi Roberts <mia@naomieow.xyz>

lesbian.skin 354a1e82 4c922dea

verified
+37 -34
+4 -6
gleam.toml
··· 5 5 licences = ["MIT"] 6 6 repository = { type = "github", user = "nootr", repo = "glimit" } 7 7 target = "erlang" 8 - internal_modules = [ 9 - "glimit/*", 10 - ] 8 + internal_modules = ["glimit/*"] 11 9 12 10 [dependencies] 13 - gleam_stdlib = ">= 0.34.0 and < 2.0.0" 14 - gleam_erlang = ">= 0.25.0 and < 1.0.0" 15 - gleam_otp = ">= 0.11.2 and < 1.0.0" 11 + gleam_stdlib = ">= 0.62.0 and < 2.0.0" 12 + gleam_erlang = ">= 1.3.0 and < 2.0.0" 13 + gleam_otp = ">= 1.1.0 and < 2.0.0" 16 14 17 15 [dev-dependencies] 18 16 gleeunit = ">= 1.0.0 and < 2.0.0"
+7 -7
manifest.toml
··· 2 2 # You typically do not need to edit this file 3 3 4 4 packages = [ 5 - { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, 6 - { name = "gleam_otp", version = "0.11.2", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "517FFB679E44AD71D059F3EF6A17BA6EFC8CB94FA174D52E22FB6768CF684D78" }, 7 - { name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" }, 8 - { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, 5 + { name = "gleam_erlang", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "1124AD3AA21143E5AF0FC5CF3D9529F6DB8CA03E43A55711B60B6B7B3874375C" }, 6 + { name = "gleam_otp", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "7987CBEBC8060B88F14575DEF546253F3116EBE2A5DA6FD82F38243FCE97C54B" }, 7 + { name = "gleam_stdlib", version = "0.62.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "0080706D3A5A9A36C40C68481D1D231D243AF602E6D2A2BE67BA8F8F4DFF45EC" }, 8 + { name = "gleeunit", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "FDC68A8C492B1E9B429249062CD9BAC9B5538C6FBF584817205D0998C42E1DAC" }, 9 9 ] 10 10 11 11 [requirements] 12 - gleam_erlang = { version = ">= 0.25.0 and < 1.0.0" } 13 - gleam_otp = { version = ">= 0.11.2 and < 1.0.0" } 14 - gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } 12 + gleam_erlang = { version = ">= 1.3.0 and < 2.0.0" } 13 + gleam_otp = { version = ">= 1.1.0 and < 2.0.0" } 14 + gleam_stdlib = { version = ">= 0.62.0 and < 2.0.0" } 15 15 gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
+10 -7
src/glimit/rate_limiter.gleam
··· 75 75 SetNow(now: Int) 76 76 } 77 77 78 - fn handle_message(message: Message, state: State) -> actor.Next(Message, State) { 78 + fn handle_message(state: State, message: Message) -> actor.Next(State, Message) { 79 79 case message { 80 - Shutdown -> actor.Stop(process.Normal) 80 + Shutdown -> actor.stop() 81 81 82 82 Hit(client) -> { 83 83 let state = refill_bucket(state) ··· 107 107 pub fn new( 108 108 max_token_count: Int, 109 109 token_rate: Int, 110 - ) -> Result(Subject(Message), Nil) { 110 + ) -> Result(actor.Started(Subject(Message)), Nil) { 111 111 let state = 112 112 State( 113 113 max_token_count: max_token_count, ··· 116 116 last_update: None, 117 117 now: None, 118 118 ) 119 - actor.start(state, handle_message) 120 - |> result.nil_error 119 + actor.start( 120 + actor.new(state) 121 + |> actor.on_message(handle_message), 122 + ) 123 + |> result.replace_error(Nil) 121 124 } 122 125 123 126 /// Stop the rate limiter actor. ··· 129 132 /// Mark a hit on the rate limiter actor. 130 133 /// 131 134 pub fn hit(rate_limiter: Subject(Message)) -> Result(Nil, Nil) { 132 - actor.call(rate_limiter, Hit, 10) 135 + actor.call(rate_limiter, 10, Hit) 133 136 } 134 137 135 138 /// Returns True if the token bucket is full. 136 139 /// 137 140 pub fn has_full_bucket(rate_limiter: Subject(Message)) -> Bool { 138 - actor.call(rate_limiter, HasFullBucket, 10) 141 + actor.call(rate_limiter, 10, HasFullBucket) 139 142 } 140 143 141 144 /// Set the current time for testing purposes.
+13 -11
src/glimit/registry.gleam
··· 6 6 import gleam/list 7 7 import gleam/option.{type Option, None, Some} 8 8 import gleam/otp/actor 9 - import gleam/otp/task 10 9 import gleam/result 11 10 import glimit/rate_limiter 12 11 13 12 pub type RateLimiterRegistryActor(id) = 14 - Subject(Message(id)) 13 + actor.Started(Subject(Message(id))) 15 14 16 15 /// The rate limiter registry state. 17 16 /// ··· 57 56 state.max_token_count(identifier), 58 57 state.token_rate(identifier), 59 58 )) 60 - Ok(rate_limiter) 59 + Ok(rate_limiter.data) 61 60 } 62 61 } 63 62 } 64 63 65 64 fn handle_message( 66 - message: Message(id), 67 65 state: State(id), 68 - ) -> actor.Next(Message(id), State(id)) { 66 + message: Message(id), 67 + ) -> actor.Next(State(id), Message(id)) { 69 68 case message { 70 69 GetOrCreate(identifier, client) -> { 71 70 case handle_get_or_create(identifier, state) { ··· 113 112 registry: dict.new(), 114 113 ) 115 114 use registry <- result.try( 116 - actor.start(state, handle_message) 117 - |> result.nil_error, 115 + actor.start( 116 + actor.new(state) 117 + |> actor.on_message(handle_message), 118 + ) 119 + |> result.replace_error(Nil), 118 120 ) 119 121 120 - task.async(fn() { sweep(registry, Some(10)) }) 122 + process.spawn(fn() { sweep(registry, Some(10)) }) 121 123 122 124 Ok(registry) 123 125 } ··· 128 130 registry: RateLimiterRegistryActor(id), 129 131 identifier: id, 130 132 ) -> Result(Subject(rate_limiter.Message), Nil) { 131 - actor.call(registry, GetOrCreate(identifier, _), 10) 133 + actor.call(registry.data, 10, GetOrCreate(identifier, _)) 132 134 } 133 135 134 136 /// Return a list of rate limiters. ··· 136 138 pub fn get_all( 137 139 registry: RateLimiterRegistryActor(id), 138 140 ) -> List(#(id, Subject(rate_limiter.Message))) { 139 - actor.call(registry, GetAll, 10) 141 + actor.call(registry.data, 10, GetAll) 140 142 } 141 143 142 144 /// Remove a rate limiter from the registry. ··· 145 147 registry: RateLimiterRegistryActor(id), 146 148 identifier: id, 147 149 ) -> Result(Nil, Nil) { 148 - actor.call(registry, Remove(identifier, _), 10) 150 + actor.call(registry.data, 10, Remove(identifier, _)) 149 151 Ok(Nil) 150 152 } 151 153
+3 -3
test/glimit_rate_limiter_test.gleam
··· 4 4 pub fn rate_limiter_test() { 5 5 let assert Ok(limiter) = rate_limiter.new(2, 2) 6 6 7 - limiter 7 + limiter.data 8 8 |> rate_limiter.hit 9 9 |> should.be_ok 10 10 11 - limiter 11 + limiter.data 12 12 |> rate_limiter.hit 13 13 |> should.be_ok 14 14 15 - limiter 15 + limiter.data 16 16 |> rate_limiter.hit 17 17 |> should.be_error 18 18 }