Пример #1
0
func SwiftCancelableContext(ctx *context.T, cancelFunc context.CancelFunc) (C.GoCancelableContextHandle, error) {
	if cancelFunc == nil {
		return C.GoCancelableContextHandle(0), fmt.Errorf("Cannot create SwiftCancelableContext with nil cancel function")
	}
	ctx = context.WithValue(ctx, cancelFuncKey{}, cancelFunc)
	return C.GoCancelableContextHandle(SwiftContext(ctx)), nil
}
Пример #2
0
//export swift_io_v_v23_context_VContext_nativeWithCancel
func swift_io_v_v23_context_VContext_nativeWithCancel(ctxHandle C.GoContextHandle, errOut C.SwiftVErrorPtr) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	ctx, cancelFunc := context.WithCancel(ctx)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}
Пример #3
0
//export swift_io_v_v23_context_VContext_nativeWithTimeout
func swift_io_v_v23_context_VContext_nativeWithTimeout(ctxHandle C.GoContextHandle, nsTimeout C.double, errOut *C.SwiftVError) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	timeout := sutil.GoDuration(float64(nsTimeout))
	ctx, cancelFunc := context.WithTimeout(ctx, timeout)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}
Пример #4
0
//export swift_io_v_v23_context_VContext_nativeWithDeadline
func swift_io_v_v23_context_VContext_nativeWithDeadline(ctxHandle C.GoContextHandle, deadlineEpoch C.double, errOut C.SwiftVErrorPtr) C.GoCancelableContextHandle {
	ctx := GoContext(uint64(ctxHandle))
	deadline := sutil.GoTime(float64(deadlineEpoch))
	ctx, cancelFunc := context.WithDeadline(ctx, deadline)
	swiftCtx, err := SwiftCancelableContext(ctx, cancelFunc)
	if err != nil {
		sutil.ThrowSwiftError(ctx, err, unsafe.Pointer(errOut))
		return C.GoCancelableContextHandle(0)
	}
	return C.GoCancelableContextHandle(swiftCtx)
}