Skip to content

Latest commit

 

History

History
186 lines (107 loc) · 5.06 KB

File metadata and controls

186 lines (107 loc) · 5.06 KB

andculturecode-javascript-coreDo

Class: Do <TResourceType, TReturnVal>

Utility class to be able to use strong typing in a catch handler. the Do.catch method takes a callback where the parameters are:

  • result?: Result -- if it's an error from the server, will not be null
  • error?: any -- if it's a Javascript error, will not be null

Type parameters

TResourceType

TReturnVal

Hierarchy

  • Do

Index

Constructors

Properties

Methods

Object literals

Constructors

Private constructor

+ new Do(workload: AsyncWorkload‹TReturnVal›): Do

Defined in src/utilities/do-try.ts:23

Parameters:

Name Type
workload AsyncWorkload‹TReturnVal›

Returns: Do

Properties

Private promise

promise: Promise‹TReturnVal›

Defined in src/utilities/do-try.ts:19

Methods

catch

catch(errorHandler: CatchResultHandler‹TResourceType›): Do‹TResourceType, TReturnVal›

Defined in src/utilities/do-try.ts:46

Handle errors from the workload. If errors are in the shape of a {ResultRecord}, you will get a typed {ResultRecord} as the first parameter. Otherwise, if it's an unknown error or Javascript error, you'll get an {any} as the second parameter.

Parameters:

Name Type Description
errorHandler CatchResultHandler‹TResourceType› handle errors, either as a {ResultRecord} or {any}

Returns: Do‹TResourceType, TReturnVal›

this


finally

finally(finallyHandler: FinallyHandler): Do‹TResourceType, TReturnVal›

Defined in src/utilities/do-try.ts:75

Run some handler when the function completes, whether the catch() was hit or not.

Parameters:

Name Type
finallyHandler FinallyHandler

Returns: Do‹TResourceType, TReturnVal›

this


getAwaiter

getAwaiter(): Promise‹TReturnVal›

Defined in src/utilities/do-try.ts:89

Awaits the internal promise being tracked by the Do instance, and returns the result. This way, you can await a Do.try chain, if you need to await for the result inside of another scope, such as tests.

Returns: Promise‹TReturnVal›

the result of the promise.


Static configure

configure(config: DoTryConfig): void

Defined in src/utilities/do-try.ts:65

Sets the global configuration object for class {Do}

Parameters:

Name Type Description
config DoTryConfig the {DoTryConfig} object to set

Returns: void


Static try

try<TResourceType, TReturnVal>(workload: AsyncWorkload‹TReturnVal›): Do‹TResourceType, TReturnVal›

Defined in src/utilities/do-try.ts:100

Static factory method for Do class. Start a workload (sync or async) that you can then call .catch(catchHandler).finally(finallyHandler) on.

Type parameters:

TResourceType

TReturnVal

Parameters:

Name Type Description
workload AsyncWorkload‹TReturnVal› a sync or async method to wrap

Returns: Do‹TResourceType, TReturnVal›

a new instance of Do

Object literals

Static Private config

config: object

Defined in src/utilities/do-try.ts:21

defaultErrorHandler

defaultErrorHandler: undefined = undefined

Defined in src/utilities/do-try.ts:22