title: Getting error "Suspension functions can be called only within coroutine body" in Kotlin
body: <p>I've written one function with Flow collector which is as shown below,</p>
  <pre><code>private fun callSocket(
          eventEmmit: String,
          eventOn: String,
          request: JSONObject
      ): Flow&lt;SocketCallback&lt;JSONObject&gt;&gt; =
          flow {
              try {
                  if (socket.connected()) {
                      var response = JSONObject()
                      Log.e(&quot;EMIT&quot;, JSONObject(Gson().toJson(request)).toString())
  
                      socket.on(
                          eventOn
                      ) { args -&gt;
                          response = args[0] as JSONObject
                          Log.e(&quot;ON&quot;, response.toString())
                          **this.emit(SocketCallback.OnSuccess(response))**
                      }.emit(
                          eventEmmit,
                          request
                      )
                      emit(SocketCallback.OnSuccess(response))
                  } else {
                      Log.e(&quot;SOCKET_ERROR&quot;, &quot;Socket connection failed&quot;)
                      emit(SocketCallback.OnError(&quot;Socket connection failed&quot;))
                  }
              } catch (e: SocketException) {
                  emit(SocketCallback.OnError(e.toString()))
              }
          }.flowOn(Dispatchers.IO)
  </code></pre>
  <p>But when I write <strong>this.emit(SocketCallback.OnSuccess(response))</strong>(enclosed in ** in code) in <strong>on</strong> method it shows me the error &quot;Suspension functions can be called only within coroutine body&quot;.</p>
  <p>Any solution for this?</p>
  <p>Thanks in advance.</p>