import { Defer } from "https://deno.land/x/easyts@0.1.3/defer.ts";
mock golang defer
Examples
Example 1
Example 1
Defer.async(async (d) => {
const db = await openDB() // open resource
// close db
d.defer(async () => await db.close())
const f = await openFile('date.log') // open resource
// close file
d.defer(async () => await f.close())
// some logic code logic
const text = await f.readAll()
const result = await db.set('log', text)
return result // After the function returns, defer will call the registered cleanup function according to the first in, last out
})
Methods
private
_asyncDone()private
_syncDone(): voiddefer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
v19: T19,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
v19: T19,
defer<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(): Cancel
f: () => any | Promise<any>,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
v19: T19,
v20: T20,
v1: T1,
v2: T2,
v3: T3,
v4: T4,
v5: T5,
v6: T6,
v7: T7,
v8: T8,
v9: T9,
v10: T10,
v11: T11,
v12: T12,
v13: T13,
v14: T14,
v15: T15,
v16: T16,
v17: T17,
v18: T18,
v19: T19,
v20: T20,