Skip to content

Commit

Permalink
Merge pull request #119 from maxtori/nodejs-callback-type
Browse files Browse the repository at this point in the history
fix nodejs callback type
  • Loading branch information
maxtori authored Aug 9, 2023
2 parents 1300836 + 722bed0 commit fed22b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,30 @@ jobs:
matrix:
os:
- ubuntu-latest
ocaml-version:
- macos-latest
ocaml-compiler:
- 4.14.1

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Retrieve opam cache
uses: actions/cache@v2
id: cache-opam
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
path: ~/.opam
key: v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-${{ hashFiles('ez_api.opam') }}
restore-keys: |
v1-${{ runner.os }}-opam-${{ matrix.ocaml-version }}-
- name: Use OCaml ${{ matrix.ocaml-version }}
uses: avsm/setup-ocaml@v1
with:
ocaml-version: ${{ matrix.ocaml-version }}
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Install system packages required by opam packages
run: opam depext --yes --update geoip ocurl tls
run: opam depext --update geoip ocurl tls

- name: Install opam packages
if: steps.cache-opam.outputs.cache-hit != 'true'
run: |
opam pin add websocket-httpaf.~dev https://github.com/anmonteiro/websocket-httpaf.git
opam pin add websocket-httpaf-lwt.~dev https://github.com/anmonteiro/websocket-httpaf.git
opam install $(opam show -f depopts: . | sed -e 's/{.*}//g' -e 's/"//g')
opam install . --deps-only --with-doc --with-test
- name: Check the consistency of installed opam packages
if: steps.cache-opam.outputs.cache-hit == 'true'
run: opam upgrade --fixup

- name: Run build
run: opam exec -- make build
6 changes: 3 additions & 3 deletions src/request/js/nodejs/nodejs_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class type message = object
method statusCode : int readonly_prop
method statusMessage : js_string t readonly_prop
method url : js_string t readonly_prop
method on_data : js_string t -> (js_string t -> unit) callback -> unit meth
method on_data : js_string t -> (Typed_array.arrayBuffer t -> unit) callback -> unit meth
method on_end : js_string t -> (unit -> unit) callback -> unit meth
end

Expand Down Expand Up @@ -56,7 +56,7 @@ let handle f (m : message t) =
if m##.statusCode >= 200 && m##.statusCode < 300 then
let s = ref "" in
m##on_data (string "data") (wrap_callback (fun chunk ->
s := !s ^ (to_string chunk)));
s := !s ^ (Typed_array.String.of_arrayBuffer chunk)));
m##on_end (string "end") (wrap_callback (fun () ->
if !Verbose.v land 1 <> 0 then Format.printf "[ez_api] received:\n%s@." !s;
f (Ok !s)))
Expand All @@ -75,7 +75,7 @@ let get ?(protocol=http) ?options url f =
let post ?(protocol=http) ?options url ~content f =
if !Verbose.v land 2 <> 0 then Format.printf "[ez_api] sent:\n%s@." content;
let o = optdef options_to_jsoo options in
let req = protocol##get (string url) o (def @@ wrap_callback (handle f)) in
let req = protocol##request (string url) o (def @@ wrap_callback (handle f)) in
req##on_error (string "error") (wrap_callback (fun (e : err t) ->
f (Error (e##.code, Some (to_string e##.message)))));
req##end_ (def (string content))
Expand Down

0 comments on commit fed22b0

Please sign in to comment.