Skip to content

Commit 230c7bf

Browse files
committed
Add await with _s functions to metacall C API.
1 parent 2f553ad commit 230c7bf

File tree

2 files changed

+236
-98
lines changed

2 files changed

+236
-98
lines changed

source/metacall/include/metacall/metacall.h

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,40 @@ METACALL_API int metacall_registerv(const char * name, void * (*invoke)(size_t,
686686
*/
687687
METACALL_API void * metacall_await(const char * name, void * args[], void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
688688

689+
/**
690+
* @brief
691+
* Executes an asynchronous call to the function and registers a callback to be executed when a future is resolved (it does block)
692+
*
693+
* @param[in] name
694+
* The name of the function to be called asynchronously
695+
*
696+
* @param[in] args
697+
* Array of pointers to the values to be passed to the function
698+
*
699+
* @param[in] size
700+
* Number of elements of the array @args
701+
*
702+
* @param[in] resolve_callback
703+
* Pointer to function that will be executed when task completion
704+
* @param[in] void *
705+
* Value representing the result of the future resolution
706+
* @param[in] void *
707+
* A reference to @data that will be used as a closure for the chain
708+
* @return
709+
* Value containing the result of the operation,
710+
* it will be wrapped into a future later on to be returned by the function
711+
*
712+
* @param[in] reject_callback
713+
* Pointer to function that will be executed when task error (signature is identical as resolve_callback)
714+
*
715+
* @param[in] data
716+
* Pointer to a context that will act as a closure for the chain
717+
*
718+
* @return
719+
* Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future
720+
*/
721+
METACALL_API void * metacall_await_s(const char * name, void * args[], size_t size, void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
722+
689723
/**
690724
* @brief
691725
* Call an asynchronous function anonymously by value array @args and function @func
@@ -719,19 +753,16 @@ METACALL_API void * metacallfv_await(void * func, void * args[], void * (*resolv
719753

720754
/**
721755
* @brief
722-
* Call an asynchronous function anonymously by function @func and serial @buffer of size @size
756+
* Call an asynchronous function anonymously by value array @args and function @func
723757
*
724758
* @param[in] func
725759
* Reference to function to be called
726760
*
727-
* @param[in] buffer
728-
* String representing an array to be deserialized into arguments of the function
761+
* @param[in] args
762+
* Array of pointers to values
729763
*
730764
* @param[in] size
731-
* Size of string @buffer
732-
*
733-
* @param[in] allocator
734-
* Pointer to allocator will allocate the value
765+
* Number of elements of the array @args
735766
*
736767
* @param[in] resolve_callback
737768
* Pointer to function that will be executed when task completion
@@ -752,7 +783,7 @@ METACALL_API void * metacallfv_await(void * func, void * args[], void * (*resolv
752783
* @return
753784
* Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future
754785
*/
755-
METACALL_API void * metacallfs_await(void * func, const char * buffer, size_t size, void * allocator, void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
786+
METACALL_API void * metacallfv_await_s(void * func, void * args[], size_t size, void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
756787

757788
/**
758789
* @brief
@@ -767,6 +798,9 @@ METACALL_API void * metacallfs_await(void * func, const char * buffer, size_t si
767798
* @param[in] values
768799
* Array of values representing argument values data
769800
*
801+
* @param[in] size
802+
* Number of elements of the arrays @keys and @values
803+
*
770804
* @param[in] resolve_callback
771805
* Pointer to function that will be executed when task completion
772806
* @param[in] void *
@@ -788,6 +822,77 @@ METACALL_API void * metacallfs_await(void * func, const char * buffer, size_t si
788822
*/
789823
METACALL_API void * metacallfmv_await(void * func, void * keys[], void * values[], void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
790824

825+
/**
826+
* @brief
827+
* Call an asynchronous function anonymously by value map (@keys -> @values) and function @func
828+
*
829+
* @param[in] func
830+
* Reference to function to be called
831+
*
832+
* @param[in] keys
833+
* Array of values representing argument keys
834+
*
835+
* @param[in] values
836+
* Array of values representing argument values data
837+
*
838+
* @param[in] resolve_callback
839+
* Pointer to function that will be executed when task completion
840+
* @param[in] void *
841+
* Value representing the result of the future resolution
842+
* @param[in] void *
843+
* A reference to @data that will be used as a closure for the chain
844+
* @return
845+
* Value containing the result of the operation,
846+
* it will be wrapped into a future later on to be returned by the function
847+
*
848+
* @param[in] reject_callback
849+
* Pointer to function that will be executed when task error (signature is identical as resolve_callback)
850+
*
851+
* @param[in] data
852+
* Pointer to a context that will act as a closure for the chain
853+
*
854+
* @return
855+
* Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future
856+
*/
857+
METACALL_API void * metacallfmv_await_s(void * func, void * keys[], void * values[], size_t size, void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
858+
859+
/**
860+
* @brief
861+
* Call an asynchronous function anonymously by function @func and serial @buffer of size @size
862+
*
863+
* @param[in] func
864+
* Reference to function to be called
865+
*
866+
* @param[in] buffer
867+
* String representing an array to be deserialized into arguments of the function
868+
*
869+
* @param[in] size
870+
* Size of string @buffer
871+
*
872+
* @param[in] allocator
873+
* Pointer to allocator will allocate the value
874+
*
875+
* @param[in] resolve_callback
876+
* Pointer to function that will be executed when task completion
877+
* @param[in] void *
878+
* Value representing the result of the future resolution
879+
* @param[in] void *
880+
* A reference to @data that will be used as a closure for the chain
881+
* @return
882+
* Value containing the result of the operation,
883+
* it will be wrapped into a future later on to be returned by the function
884+
*
885+
* @param[in] reject_callback
886+
* Pointer to function that will be executed when task error (signature is identical as resolve_callback)
887+
*
888+
* @param[in] data
889+
* Pointer to a context that will act as a closure for the chain
890+
*
891+
* @return
892+
* Pointer to value containing the result of the call returned by @resolve_callback or @reject_callback wrapped in a future
893+
*/
894+
METACALL_API void * metacallfs_await(void * func, const char * buffer, size_t size, void * allocator, void * (*resolve_callback)(void *, void *), void * (*reject_callback)(void *, void *), void * data);
895+
791896
/**
792897
* @brief
793898
* Call an asynchronous function anonymously by function @func and serial @buffer of size @size

0 commit comments

Comments
 (0)