Browse Source

onconnect callback

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

7
app.ts

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

39
dist/src/grpc/index.js

@ -136,30 +136,29 @@ 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++;
ctx = innerCtx;
i++;
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions();
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`);
try {
yield network.initGrpcSubscriptions();
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`);
resolve();
console.log(`=> [lnd] connected! ${now}`);
if (callback)
callback();
}
catch (e) {
if (e.code === ERR_CODE_UNIMPLEMENTED) {
// await tryToUnlockLND()
}
catch (e) {
if (e.code === ERR_CODE_UNIMPLEMENTED) {
// await tryToUnlockLND()
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
if (ctx === innerCtx) { // if another retry fires, then this will not run
yield reconnectToLND(innerCtx);
}
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
if (ctx === innerCtx) { // if another retry fires, then this will not run
yield reconnectToLND(innerCtx);
}
}), 2000);
}
}));
}), 2000);
}
});
}
exports.reconnectToLND = reconnectToLND;

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

File diff suppressed because one or more lines are too long

38
src/grpc/index.ts

@ -131,27 +131,25 @@ export function subscribeInvoices(parseKeysendInvoice) {
var i = 0
var ctx = 0
export async function reconnectToLND(innerCtx:number) {
return new Promise( async (resolve,reject)=>{
ctx = innerCtx
i++
export async function reconnectToLND(innerCtx:number, callback?:Function) {
ctx = innerCtx
i++
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`)
try {
await network.initGrpcSubscriptions()
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> ${now} [lnd] reconnecting... attempt #${i}`)
try {
await network.initGrpcSubscriptions()
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`=> [lnd] connected! ${now}`)
resolve()
} catch(e) {
if(e.code===ERR_CODE_UNIMPLEMENTED) {
// await tryToUnlockLND()
}
setTimeout(async()=>{ // retry each 2 secs
if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000)
console.log(`=> [lnd] connected! ${now}`)
if(callback) callback()
} catch(e) {
if(e.code===ERR_CODE_UNIMPLEMENTED) {
// await tryToUnlockLND()
}
})
setTimeout(async()=>{ // retry each 2 secs
if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000)
}
}

Loading…
Cancel
Save