Skip to content

Commit

Permalink
feat: 🎸 add chainsync(background task)
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Dec 26, 2023
1 parent e9aa70d commit 6d8adb4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { RootController } from './root/root.controller';
import { RootService } from './root/root.service';
import { ChainsyncService } from './chainsync/chainsync.service';

@Module({
imports: [],
controllers: [RootController],
providers: [RootService],
providers: [RootService, ChainsyncService],
})
export class AppModule {}
25 changes: 25 additions & 0 deletions src/chainsync/chainsync.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Injectable, OnModuleInit } from '@nestjs/common';

@Injectable()
export class ChainsyncService implements OnModuleInit {
async onModuleInit() {
await this.startBackgroundTask();
}

private async startBackgroundTask() {
while (true) {
try {
console.log(
'Always craw the lastest tipset ,blockMessages and messages ',
);
await this.delay(1000);
} catch (error) {
console.error('Error in background task:', error);
}
}
}

private async delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}

0 comments on commit 6d8adb4

Please sign in to comment.