* Add '@lumeweb/libkernel-universal' as dependency and make socket.ts asynchronous using 'maybeGetAsyncProperty'.

This commit is contained in:
Derrick Hammer 2023-04-09 00:50:14 -04:00
parent 1dedb7b240
commit 50271fad44
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 8 additions and 6 deletions

View File

@ -27,6 +27,7 @@
"@libp2p/utils": "^3.0.7",
"@lumeweb/kernel-protomux-client": "git+https://git.lumeweb.com/LumeWeb/kernel-protomux-client.git",
"@lumeweb/kernel-swarm-client": "git+https://git.lumeweb.com/LumeWeb/kernel-swarm-client.git",
"@lumeweb/libkernel-universal": "git+https://git.lumeweb.com/LumeWeb/libkernel-universal.git",
"@multiformats/mafmt": "^11.1.2",
"@peculiar/webcrypto": "git+https://git.lumeweb.com/LumeWeb/webcrypto.git",
"b4a": "^1.6.3",

View File

@ -3,6 +3,7 @@ import { TcpSocketConnectOpts } from "net";
import { PeerEntity, SocketRequest, WriteSocketRequest } from "./types.js";
import PeerManager from "./peerManager.js";
import { clearTimeout } from "timers";
import { maybeGetAsyncProperty } from "@lumeweb/libkernel-universal";
const asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
@ -50,8 +51,8 @@ export class Socket extends Duplex {
return this._peer;
}
public _write(data: any, cb: any): void {
this._peer.messages.writeSocket?.send({
public async _write(data: any, cb: any): Promise<void> {
(await maybeGetAsyncProperty(this._peer.messages.writeSocket))?.send({
id: this._id,
remoteId: this._remoteId,
data,
@ -59,8 +60,8 @@ export class Socket extends Duplex {
cb();
}
public _destroy(cb: Callback) {
this._peer.messages.closeSocket?.send({
public async _destroy(cb: Callback) {
(await maybeGetAsyncProperty(this._peer.messages.closeSocket))?.send({
id: this._id,
remoteId: this._remoteId,
} as SocketRequest);
@ -68,8 +69,8 @@ export class Socket extends Duplex {
this._manager.sockets.delete(this._id);
}
public connect() {
this._peer.messages.openSocket?.send({
public async connect() {
(await maybeGetAsyncProperty(this._peer.messages.openSocket))?.send({
...this._options,
id: this._id,
});