Skip to content

Commit

Permalink
fix(deno): deserialize module.client
Browse files Browse the repository at this point in the history
  • Loading branch information
Uskrai committed Oct 3, 2022
1 parent 8ea09ec commit c006c37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
10 changes: 6 additions & 4 deletions crates/deno/script/deps/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export class HttpResponse {
}

export class HttpClient extends Resource {
constructor(rid = null) {
constructor(rid: number = null) {
if (rid == null) {
rid = Deno.core.opSync("op_http_client_new");
}

super(rid, "op_http_client");
}

Expand All @@ -61,12 +62,13 @@ export class HttpClient extends Resource {
);
}

close() {
this.decrement_strong_count();
close(): Result<void> {
return this.decrement_strong_count();
}

clone() {
return new HttpClient(ResultFromJson(this.increment_strong_count()).data);
let rid = this.increment_strong_count();
return new HttpClient(rid);
}
}

Expand Down
19 changes: 4 additions & 15 deletions crates/deno/script/deps/resource.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Errors } from "./error";
import { Result, ResultFromJson } from "./error";

function fromPrefix(res: Resource, add: string) {
return `${res.prefix}_${add}`;
}

export class Resource {
strong_rid: Array<number>;
constructor(public rid: number, public prefix: string) {
this.strong_rid = [rid];
}

// get rid() {
Expand All @@ -20,21 +18,12 @@ export class Resource {
// return rid;
// }

get last_rid() {
return this.strong_rid.at(-1);
}

increment_strong_count() {
let rid = Deno.core.opSync(fromPrefix(this, "clone"), this.rid);
this.strong_rid.push(rid);
let rid = ResultFromJson(Deno.core.opSync(fromPrefix(this, "clone"), this.rid)).data;
return rid;
}

decrement_strong_count() {
Deno.core.opSync(fromPrefix(this, "close"), this.last_rid);

if (this.strong_rid.length == 0) {
this.rid = null;
}
decrement_strong_count(): Result<void> {
return ResultFromJson(Deno.core.opSync(fromPrefix(this, "close"), this.rid));
}
}

0 comments on commit c006c37

Please sign in to comment.