Giter VIP home page Giter VIP logo

nats.ocaml's Introduction

nats.ocaml's People

Contributors

romanchechyotkin avatar dx3mod avatar

Stargazers

Andrejs Agejevs avatar Shohei Shimomura avatar Novikova Anastasia avatar Sora Morimoto avatar  avatar Seb Mondet avatar

Watchers

 avatar

Forkers

dx3mod

nats.ocaml's Issues

Design Subscriptions

A subscription system needs to be designed. How it should look like and how it should work.

Ideas that come to mind

  • Callbacks. But how to make it work in the background? And that requires a mutable state
     client#sub ~subject"FOO.*" (fun event -> ...)
  • Blocking listener (bad idea) something like
     client#listen (fun any_event -> ...)

A real-world example would be nice. And a list of tasks that need to be covered.

Improve library API

Some suggestions for improving library's API.

Labeled functions

(* now *)
Client.connect host port
(* with labeled arguments *)
Client.connect ~host ~port ()

You can also set defaults for them

(* now *)
let connect host port = ...
(* with defaults *)
let connect ?(host = default_host) ?(port = default_port) () = ...

or use modules

let conn = Client.connect (module struct 
  let host = ..
  let port = ...
 end)

with_connect

Automatically close a resource

(* now *) 
let conn = Client.connect ()
...
Client.close conn

(* with with_connect *)
Client.with_connect ... @@ fun conn -> 
  ...

first-class modules or objects for connection

(* object *)
Client.with_connect ~host ~port (fun conn -> 
  conn#pub "FOO")

(* first-class module *)
Client.with_connect ~host ~port (fun (module Conn) -> 
  Conn.pub "FOO")

signature for abstraction

(* now *)
type 'a t = { sockaddr : sockaddr; socket : Lwt_unix.file_descr }
(* should be *)
type 'a t

Module signatures hide internal implementation.

unsafe

In some cases you can use unsafe functions (read this)

(* now *)
let msg : bytes = Bytes.of_string message 
(* better performance *)  
let msg  = Bytes.unsafe_of_string message 

print_endline

๐ŸŒต

monadic syntax

Prefer monadic syntax let*, let+, or ppx_lwt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.