Skip to content

Commit 4174f19

Browse files
committed
update README.md
1 parent 2726963 commit 4174f19

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ A resource is a unique identifier for a rate-limited entity. It is used to track
1818
A wrapper class that accepts a resource and applies the rate limit to it. It is used to control the rate limit for accessing a specific resource , by calling the `wait()` method before accessing the resource.
1919

2020
## Example
21-
See more in `DoormanClientTest.kt`
21+
22+
#### Basic Usage
2223
```kotlin
2324
runBlocking {
2425
val client = DoormanClient.create("example-client")
@@ -46,4 +47,82 @@ runBlocking {
4647

4748
scope.cancelAndJoin() // close the tracker coroutine.
4849
}
50+
```
51+
52+
#### Where it shines
53+
```kotlin
54+
55+
runBlocking {
56+
/*
57+
This assumes that there is a resource as defined below in the doorman server
58+
- identifier_glob: fair
59+
capacity: 1000
60+
safe_capacity: 10
61+
description: fair share example
62+
algorithm:
63+
kind: FAIR_SHARE
64+
lease_length: 60
65+
refresh_interval: 5 // keeping this small for testing purposes.
66+
*/
67+
val small1Client = DoormanClient.create("small1Client-client")
68+
val small1Resource = small1Client.requestResource("fair",100.0)
69+
70+
val small2Client = DoormanClient.create("small2Client-client")
71+
val small2Resource = small2Client.requestResource("fair",100.0)
72+
73+
val small3Client = DoormanClient.create("small3Client-client")
74+
val small3Resource = small3Client.requestResource("fair",100.0)
75+
76+
val small4Client = DoormanClient.create("small4Client-client")
77+
val small4Resource = small4Client.requestResource("fair",100.0)
78+
79+
val bigClient = DoormanClient.create("bigClient-client")
80+
val bigResource = bigClient.requestResource("fair",1000.0)
81+
82+
delay(5000)
83+
84+
val biggerClient = DoormanClient.create("biggerClient-client")
85+
val biggerResource = biggerClient.requestResource("fair",2000.0)
86+
87+
println("Initially...")
88+
println("New Capacity of small1: ${small1Resource.lease?.capacity}")
89+
println("New Capacity of small2: ${small2Resource.lease?.capacity}")
90+
println("New Capacity of small3: ${small3Resource.lease?.capacity}")
91+
println("New Capacity of small4: ${small4Resource.lease?.capacity}")
92+
println("New Capacity of big: ${bigResource.lease?.capacity}")
93+
println("New Capacity of bigger: ${biggerResource.lease?.capacity}")
94+
95+
delay(8000)
96+
97+
println("After 8 seconds...")
98+
println("New Capacity of small1: ${small1Resource.lease?.capacity}")
99+
println("New Capacity of small2: ${small2Resource.lease?.capacity}")
100+
println("New Capacity of small3: ${small3Resource.lease?.capacity}")
101+
println("New Capacity of small4: ${small4Resource.lease?.capacity}")
102+
println("New Capacity of big: ${bigResource.lease?.capacity}")
103+
println("New Capacity of bigger: ${biggerResource.lease?.capacity}")
104+
105+
}
106+
```
107+
108+
#### Output
109+
```text
110+
Initially...
111+
New Capacity of small1: 100.0
112+
New Capacity of small2: 100.0
113+
New Capacity of small3: 100.0
114+
New Capacity of small4: 100.0
115+
New Capacity of big: 600.0
116+
New Capacity of bigger: 0.0
117+
118+
...
119+
...
120+
121+
After 8 seconds...
122+
New Capacity of small1: 100.0
123+
New Capacity of small2: 100.0
124+
New Capacity of small3: 100.0
125+
New Capacity of small4: 100.0
126+
New Capacity of big: 300.0
127+
New Capacity of bigger: 300.0
49128
```

0 commit comments

Comments
 (0)