scopsy / await-to-js

Async await wrapper for easy error handling without try-catch
http://blog.grossman.io/how-to-write-async-await-without-try-catch-blocks-in-javascript/
MIT License
3.27k stars 153 forks source link

should return an error if passed object is not a promise #15

Closed agarwalkartik closed 5 years ago

agarwalkartik commented 6 years ago

If the passed object is not a promise then to() should return an error. This feature is quite useful when using await-to-js in a non type script environment.

json2d commented 6 years ago

I personally find the await fuzzy type handling helpful in some cases. Would be nice to preserve that behavior with to()

eg.

let fuzzyAsync = async (maybePromiseFn) => await maybePromiseFn()
agarwalkartik commented 6 years ago

@bitstrider Hey, I didn't understand you, can you be little more descriptive with "await fuzzy type" handling

json2d commented 6 years ago

@agarwalkartik I give a better example in the issue here #17 if that helps.

My argument is that the normal behavior when awaiting a non-promise type is to simply let the it pass through, and so this should be the same with on().

// the desired behavior
const A = await 42; //> 42
const [err, B] = await on(42); //> [null, 42]
agarwalkartik commented 6 years ago

@bitstrider Yes I agree, any ideas on how can we implement it in this library?

json2d commented 6 years ago

@agarwalkartik I ended up creating a new project to implement the feature since this project seems to be unmaintained https://github.com/bitstrider/await-on

scopsy commented 5 years ago

Not exactly sure that the library should support this fuzziness. feel free to create your own helper function suited for your needs. This is library is about sharing a concept and the use of it should not be tied to specific implementation.