Created
January 12, 2021 22:50
-
-
Save vaidd4/22131e7bd061b85ca1c919163a6a688e to your computer and use it in GitHub Desktop.
Revisions
-
vaidd4 created this gist
Jan 12, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ function cbtoasync(fncb, ...params) { return new Promise((res, rej) => { fncb(...params, (...data) => {res(...data)}) }) } function tr_cbtoasync(fncb) { return (...data) => cbtoasync(fncb, ...data) } /* Tests */ function testcb(data, cb) { cb(data) } testcb("hello", d => console.log(d + " world")) cbtoasync(testcb, "hi").then(d => d + " dude").then(console.log) const test = tr_cbtoasync(testcb) test("yo").then(d => d + " bud").then(console.log) ;(async () => { const h = await test("hola") console.log(h + " amigo") })()