This feature is not supported on the Wolfram Cloud.

int WSWaitForLinkActivityWithCallback(WSLINK l, WSLinkWaitCallBackObject callback)
does not return until the WSTP connection specified by l has data to read, but periodically calls back to the function passed as callback.


  • Use WSWaitForLinkActivityWithCallback() on a background thread that needs to wait for data in order not to block any user interface or main threads of the application.
  • Use WSWaitForLinkActivityWithCallback() (or the related function WSWaitForLinkActivity()) when needing to wait for link activity on a link that is enabled for logging.
  • WSWaitForLinkActivityWithCallback() returns WSWAITERROR in the event of an error and WSWAITSUCCESS if the function succeeds.
  • WSLinkWaitCallBackObject is a pointer to a function of the form int function(WSINK, void *). The second argument is reserved for future use. If the function returns 1, WSWaitForLinkActivityWithCallback() will return WSWAITCALLBACKABORTED.
  • MWaitForLinkActivityWithCallback() is declared in the WSTP header file wstp.h.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

#include "wstp.h"

/* A function for WSTP to call back to while waiting */
int WaitFunction(WSINK l, void *future)
    /* By default do not back out of
        WSWaitForLinkActivityWithCallback(). */
    return 0;

/* A function for waiting for link activity */

void f(WSINK l)
    switch(WSWaitForLinkActivityWithCallBack(l, WaitFunction))
        case WSWAITERROR:
            /* Handle the error */
        case WSWAITSUCCESS:
            /* Now read incoming data */
            /* WaitFunction decided to abort the wait. */
Introduced in 2014