MCPcopy Create free account
hub / github.com/RedisGears/RedisGears / futureContinue

Function futureContinue

plugins/python/redisgears_python.c:2050–2108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2048}
2049
2050static PyObject* futureContinue(PyObject *self, PyObject *args){
2051 if(PyTuple_Size(args) != 1){
2052 PyErr_SetString(GearsError, "Continue function expect an object");
2053 return NULL;
2054 }
2055
2056 PyFuture* pyFuture = (PyFuture*)self;
2057 if(!pyFuture->asyncRecord){
2058 PyErr_SetString(GearsError, "Can not continue with the same future twice");
2059 return NULL;
2060 }
2061
2062 Record* record = NULL;
2063
2064 PyObject* obj = PyTuple_GetItem(args, 0);
2065 switch(pyFuture->continueType){
2066 case ContinueType_Default:
2067 Py_INCREF(obj);
2068 record = PyObjRecordCreate();
2069 PyObjRecordSet(record, obj);
2070 break;
2071 case ContinueType_Filter:
2072 if(PyObject_IsTrue(obj)){
2073 record = RedisGears_GetDummyRecord(); // everithing other then NULL will be true;
2074 }
2075 break;
2076 case ContinueType_Flat:
2077 if(PyList_Check(obj)){
2078 size_t len = PyList_Size(obj);
2079 record = RedisGears_ListRecordCreate(len);
2080 for(size_t i = 0 ; i < len ; ++i){
2081 PyObject* temp = PyList_GetItem(obj, i);
2082 Record* pyRecord = PyObjRecordCreate();
2083 Py_INCREF(temp);
2084 PyObjRecordSet(pyRecord, temp);
2085 RedisGears_ListRecordAdd(record, pyRecord);
2086 }
2087 }else{
2088 // just a normal pyobject
2089 Py_INCREF(obj);
2090 record = PyObjRecordCreate();
2091 PyObjRecordSet(record, obj);
2092 }
2093 break;
2094 case ContinueType_Foreach:
2095 record = RedisGears_GetDummyRecord(); // continue with the old record
2096 break;
2097 default:
2098 PyErr_SetString(GearsError, "Can not handle future untill it returned from the callback");
2099 return NULL;
2100 break;
2101 }
2102
2103 RedisGears_AsyncRecordContinue(pyFuture->asyncRecord, record);
2104 pyFuture->asyncRecord = NULL;
2105
2106 Py_INCREF(Py_None);
2107 return Py_None;

Callers

nothing calls this directly

Calls 2

PyObjRecordCreateFunction · 0.85
PyObjRecordSetFunction · 0.85

Tested by

no test coverage detected