class Fibonacci
- Fibonacci
- Reference
- Object
Defined in:
fibonacci.crversion.cr
Constant Summary
-
VERSION =
"1.0.0"
Instance Method Summary
-
#fibonacci(x)
This implements an iterative solution to solving for a given fibonacci number.
-
#run
In this example, the HTTP server that handles fibonacci requests is spawned into it's own fiber.
-
#wait
This is not strictly necessary, but in a larger application, one might want to have the main fiber wait for the fiber that is running the server to finish, and if it does so, cleanup resources.
Instance Method Detail
This implements an iterative solution to solving for a given fibonacci number. This function will also utilize BigInt, which is an arbitrary precision integer, if the answer will be too large to fit into a 64 bit Integer.
In this example, the HTTP server that handles fibonacci requests is spawned into it's own fiber. This example would work just fine if it were kept in the main thread, but this pattern can be useful in larger applications.
This example could be much shorter, but it represents a more typical application pattern, with handlers for managing errors, for logging responses, and for automatically compressing the response, if the request allows for it in the Accept-Encoding header.
This is not strictly necessary, but in a larger application, one might want to have the main fiber wait for the fiber that is running the server to finish, and if it does so, cleanup resources. This pattern is a simple one to allow that.