@internetarchive/promised-singleton
Advanced tools
Comparing version 0.2.0-alpha.1 to 0.2.0
@@ -37,2 +37,3 @@ import { __awaiter } from "tslib"; | ||
if (this.cachedResponse) { | ||
console.debug('cachedResponse found, returning'); | ||
return this.cachedResponse; | ||
@@ -42,3 +43,5 @@ } | ||
if (this.previousPromise) { | ||
console.debug('previousPromise found, chaining'); | ||
this.previousPromise = this.previousPromise.then(response => { | ||
console.debug('previousPromise completed, returning'); | ||
return response; | ||
@@ -55,3 +58,5 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.debug('generateSingleton start'); | ||
const result = yield this.generator(); | ||
console.debug('singleton generated'); | ||
this.cachedResponse = result; | ||
@@ -58,0 +63,0 @@ return result; |
{ | ||
"name": "@internetarchive/promised-singleton", | ||
"version": "0.2.0-alpha.1", | ||
"version": "0.2.0", | ||
"description": "A class for lazy-loading singletons.", | ||
@@ -5,0 +5,0 @@ "author": "promised-singleton", |
@@ -39,4 +39,4 @@ [![Build Status](https://travis-ci.com/internetarchive/iaux-promised-singleton.svg?branch=master)](https://travis-ci.com/internetarchive/iaux-promised-singleton) [![codecov](https://codecov.io/gh/internetarchive/iaux-promised-singleton/branch/master/graph/badge.svg)](https://codecov.io/gh/internetarchive/iaux-promised-singleton) | ||
// Use the PromisedSingleton object with the type of object you will be returning | ||
fooService: PromisedSingleton<FooService> = new PromisedSingleton<FooService>({ | ||
// Using a Promise | ||
fooService = new PromisedSingleton<FooService>({ | ||
generator: (): Promise<FooService> => new Promise(resolve => { | ||
@@ -49,4 +49,4 @@ const service = new FooService(); | ||
// Using an async function | ||
barService: PromisedSingleton<BarService> = new PromisedSingleton<BarService>({ | ||
generator: async (): Promise<FooService> => { | ||
barService = new PromisedSingleton<BarService>({ | ||
generator: async (): Promise<BarService> => { | ||
const service = new BarService(); | ||
@@ -53,0 +53,0 @@ await service.setup(); |
Sorry, the diff of this file is not supported yet
278039
2978