Skip to content

Dart package for simple cached isolate computations I use in various projects. It is not the best approach, just simple one

License

Notifications You must be signed in to change notification settings

bgoncharuck/cached_calc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Install: Dart

dependencies:
  cached_calc:
    git: 
      url: https://github.com/bgoncharuck/cached_calc.git
      ref: fd7877633bd60adb15f4c24432dac549ea3f5ba6

Flutter

dependencies:
  cached_calc:
    git: 
      url: https://github.com/bgoncharuck/cached_calc.git
      ref: 26a4f4a417a5c85ec70b9d7fe938c1a81fc0c5f9

Examples:

Future<FullDateZoo> calculateFullZoo(CachedCalcQuery query) async {
  return FullDateZoo.fromDate(
    query.params['dt'] as DateTime,
    query.params['tz'] as int,
  );
}

void basicCalculationTest() async {
  final fullTimeZooCache = CachedCalc<String, FullDateZoo>(
    paramsFactory: (key) {
      final cdt = CDT.fromString(key);
      return {
        'dt': cdt.toDateTime(),
        'tz': cdt.timeZone,
      };
    },
    task: calculateFullZoo,
  );

  const dates = <CDT>[
    CDT(
      year: 2001,
      month: 11,
      day: 19,
      hour: 13,
      minute: 25,
      timeZone: 6,
    ),
    CDT(
      year: 1990,
      month: 1,
      day: 28,
      hour: 0,
      minute: 2,
      timeZone: 2,
    ),
  ];

  for (int i = 0; i < dates.length; i++) {
    fullTimeZooCache.prepare(dates[i].toString()).listen((state) {
      //
      if (state.status == CachedCalcStatus.completed) {
        print(state.data as FullDateZoo);
      }
    });
  }

  for (int i = 0; i < dates.length; i++) {
    fullTimeZooCache.run(dates[i].toString());
  }
}

About

Dart package for simple cached isolate computations I use in various projects. It is not the best approach, just simple one

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages