Browse Source

onconnect callback

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
5d94ccbbf7
  1. 3
      app.ts
  2. 7
      dist/src/grpc/index.js
  3. 2
      dist/src/grpc/index.js.map
  4. 6
      src/grpc/index.ts

3
app.ts

@ -32,9 +32,10 @@ async function start(){
start()
async function connectToLND(){
await grpc.reconnectToLND(Math.random()) // recursive
grpc.reconnectToLND(Math.random(), async function(){
console.log(">> SETUP MAIN")
await mainSetup()
}) // recursive
}
async function mainSetup(){

7
dist/src/grpc/index.js

@ -136,9 +136,8 @@ function subscribeInvoices(parseKeysendInvoice) {
exports.subscribeInvoices = subscribeInvoices;
var i = 0;
var ctx = 0;
function reconnectToLND(innerCtx) {
function reconnectToLND(innerCtx, callback) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
ctx = innerCtx;
i++;
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
@ -147,7 +146,8 @@ function reconnectToLND(innerCtx) {
yield network.initGrpcSubscriptions();
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`);
resolve();
if (callback)
callback();
}
catch (e) {
if (e.code === ERR_CODE_UNIMPLEMENTED) {
@ -159,7 +159,6 @@ function reconnectToLND(innerCtx) {
}
}), 2000);
}
}));
});
}
exports.reconnectToLND = reconnectToLND;

2
dist/src/grpc/index.js.map

File diff suppressed because one or more lines are too long

6
src/grpc/index.ts

@ -131,8 +131,7 @@ export function subscribeInvoices(parseKeysendInvoice) {
var i = 0
var ctx = 0
export async function reconnectToLND(innerCtx:number) {
return new Promise( async (resolve,reject)=>{
export async function reconnectToLND(innerCtx:number, callback?:Function) {
ctx = innerCtx
i++
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
@ -141,7 +140,7 @@ export async function reconnectToLND(innerCtx:number) {
await network.initGrpcSubscriptions()
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`)
resolve()
if(callback) callback()
} catch(e) {
if(e.code===ERR_CODE_UNIMPLEMENTED) {
// await tryToUnlockLND()
@ -152,6 +151,5 @@ export async function reconnectToLND(innerCtx:number) {
}
},2000)
}
})
}

Loading…
Cancel
Save